Microsoft MVP성태의 닷넷 이야기
List<ArrarySegment<int>> 사용법 질문드립니다! [링크 복사], [링크+제목 복사],
조회: 15013
글쓴 사람
한예지 donator
홈페이지
첨부 파일
 

선생님 안녕하세요!
using System;
using System.Collections.Generic;
public class Hello1
{
    public static void Main()
    {
        int[] array = { 10, 20, 30, 40, 50, 60, 70, 80, 90 };
        
        List<ArraySegment<int>> list = new List<ArraySegment<int>>();
        
    ArraySegment<int> segment1 = new ArraySegment<int>(array, 0, 2); // 10, 20
        ArraySegment<int> segment2 = new ArraySegment<int>(array, 4, 3); // 50, 60, 70
        
        list.Add(segment1);
        list.Add(segment2);

        for(int i = 0; i < list.Count; i++)
            Console.WriteLine(list[i]);
     }
}


[출력]
System.ArraySegment`1[System.Int32]
System.ArraySegment`1[System.Int32]

[질문 1]
저는 Array에 있는 것을 일부 떼어서 ArraySegment에 각각 옮긴 후,
이것을 list에 추가하려고 합니다.
예상 출력값을 10, 20, 50, 60, 70으로 생각했지만
알 수 없는 출력값이 보입니다...
어떻게 하면 되는지 도움 부탁드립니다!








[최초 등록일: ]
[최종 수정일: 12/23/2020]


비밀번호

댓글 작성자
 



2020-12-23 11시59분
간단하게 생각해서, 다음의 값이 "1, 2, 3"으로 나오진 않습니다.

ArraySegment<int> elems = new ArraySegment<int>(new [] { 1, 2, 3 });
Console.WriteLine(elems);

결국 지난번 했던 질문과 동일한 유형입니다.

제네릭 리스트 출력하는 방법이 궁금합니다.
; https://www.sysnet.pe.kr/3/0/5414
정성태
2022-03-05 02시30분
[bbb] class Program
    {
        static void Main(string[] args)
        {
                int[] array = { 10, 20, 30, 40, 50, 60, 70, 80, 90 };

                List<ArraySegment<int>> list = new List<ArraySegment<int>>();

                ArraySegment<int> segment1 = new ArraySegment<int>(array, 0, 2); // 10, 20
                ArraySegment<int> segment2 = new ArraySegment<int>(array, 4, 3); // 50, 60, 70

                list.Add(segment1);
                list.Add(segment2);

            for (int i = 0; i < list.Count; i++)
            {
                for(int j = 0; j < list[i].Count; j++)
                Console.WriteLine(list[i].Array[list[i].Offset+j]);
            }
        }
    }
[guest]

1  2  3  4  5  6  7  8  9  10  11  12  13  [14]  15  ...
NoWriterDateCnt.TitleFile(s)
5625jaew...3/18/202213124c# 8.0 도서를 구입한 사람입니다. [1]
5624초보자3/17/202212375람다 캡처 관련 문의 [2]
5623한예지 donator3/15/202211684인터프리터 원리가 궁금합니다. [4]
5622김민아3/8/202212122const와 readonly의 명확한 차이가 이게 맞나요? [2]
5621장성욱3/8/202212223c# 로그 관련 질문 [1]
5620김민아3/7/202211631안녕하세요 비관리 객체를 반환하는 메소드 호출 시 궁금한 점이 있어서 질문드립니다 [2]
5619팡팡이3/3/202213521RSA 문의드립니다. [3]
5618김기헌3/2/202211545안녕하세요 생성자 옆에 this 키워드를 붙여 생성자를 여러 개 호출 시 질문드립니다 [2]
5617Edun2/25/202212323ArgumentOutOrRangeException에러 발생 [2]파일 다운로드1
5616csha...2/24/202211645readonly struct로 선언된 구조체를 특정 클래스에서 멤버변수로 가지는 경우 [1]
5615장성욱2/22/202215271SetThreadAffinityMask를 이용한 쓰레드 지정하는 방법에 대해 궁금합니다. [4]
5614민우2/22/202214880SSL 통신 문의 [6]
5613김인태2/22/202212966서버와 PC 간의 어플리케이션 성능 차이 [1]
5612팬입니다2/20/202211548Kastrel 서버 관련 [1]
5611차가워2/19/202211932stopWatch 늘어짐 문의 [3]
5610차가워2/18/202211837Stopwatch 늘어짐 문제 [1]
5609cs린이2/15/202211618c# 함수의 호출 방식에 대해 궁금합니다! [2]
5608지호2/10/202212607시작하세요 C# 8.0 중 제네릭타입의 IEnumerable [3]파일 다운로드1
5607이로운2/10/202211157안녕하세요. 궁금한게 있어서 질문드립니다. [1]
5605강성봉2/10/202211921TCP PSH flag 패킷 수신 에러 [1]
5604LW2/9/202212715VISUAL STUDIO 2019 ==> 2020 설치시 오류가 생겨서 문의드립니다. [3]
5603김진명2/9/202213635C# 10.0 출간은 언제쯤 계획하고 계신가요? [1]
5602신갑영2/8/202212245윈폼에 대해서 질문 드립니다. [1]
5601김인태2/4/202212211setup project 관련 [7]
5600itkim2/3/202214478윈도우 서버 계정 패스워드 인증 문의 [5]
5599레드골드2/3/202214988c#으로 ms word 제어 가능할까요? [6]
1  2  3  4  5  6  7  8  9  10  11  12  13  [14]  15  ...