Microsoft MVP성태의 닷넷 이야기
List<ArrarySegment<int>> 사용법 질문드립니다! [링크 복사], [링크+제목 복사],
조회: 13822
글쓴 사람
한예지 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]

... 16  17  [18]  19  20  21  22  23  24  25  26  27  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
5515ocm6/14/202114351mips 어셈블리 연산 [6]파일 다운로드1
5514jongs6/11/202115148GethashCode와 String대한 질문 [2]
5513labe...6/11/202114614C# Winform 에서 Label에 동일한 Color를 넣었을 때 처리방법이 궁금합니다. [2]
55126/11/202115508xlwings 가 실행조차 되지 않습니다. ㅠㅠ [7]
5511Syong6/9/202113567User Control에 string array 속성 추가하는 방법 [4]
5510jay6/8/202112831string 문자열에 쌍따옴표(")를 넣고 싶습니다. [1]파일 다운로드1
5509한예지 donator6/3/202112731ExeccuteNonQuery 질문있습니다! [2]
5508최재남6/3/202113789마우스 이벤트 관련 질문 좀 드리겠습니다. [6]
5507한예6/2/202112600static과 스택오버플로우 질문있습니다. [5]파일 다운로드1
5506이창석6/1/202114209센서의 값을 받아서 PC를 통해 모니터링 하는 것을 만들고 있습니다. [1]
5505kss5/31/202112731.net5에서 소멸자가 어떻게 바뀐건가요? [1]
5503xing...5/24/202112989xingapinet 에 수정 요청 부탁 드립니다. [1]
5501한예지 donator5/23/202113325IProgress 사용법이 궁금합니다. [2]
5500한예ㅈ5/23/202115076비동기 코드 흐름 질문있습니다. [3]
5498곰장어5/21/202113114List에 static 변수를 추가했을때의 궁금증 [3]파일 다운로드1
5497지평선5/20/202114935윈도우 배율을 알 수 있을까요? [1]
5496cs린이5/20/202112339C# 8.0 질문입니다. [2]파일 다운로드6
5495Natie5/13/202111779객체를 생성과 동시에 초기화 하는 방법 [1]
5494지예예지5/13/202114318비동기 코드 흐름이 궁금합니다! [2]
5493xing...5/6/202111958xing api XQCSPAT00600 질문입니다 [4]파일 다운로드1
5492한예지 donator5/5/202112212FromCurrentSynchronizationContext 관련 코드 질문있습니다! [2]
5491조우성5/4/202117642WinForm과 WPF의 성능차이 비교한 자료가 있을까요? [4]
5490한예지 donator5/3/202113151UI 스레드의 Invoke 질문있습니다. [4]
5489저누4/28/202113879시작하세요 C# 9.0, 225페이지 구조체 관련 질문드립니다. [2]
5488종범4/27/202113903C# 비동기 함수 async, await 와 Task의 관계에 대해 질문 드립니다. [6]
5487진우4/27/202113352C# 엑셀 자동화 성능 향상 문의 [2]
... 16  17  [18]  19  20  21  22  23  24  25  26  27  28  29  30  ...