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

... 46  47  48  49  50  51  52  53  54  55  56  [57]  58  59  60  ...
NoWriterDateCnt.TitleFile(s)
1241(non...3/22/201421049(글쓴이의 요청으로 삭제합니다.) [4]
1240이석주3/21/201423710인터넷 익스플로러가 hang이 걸리는 현상 문의 [1]파일 다운로드1
1238(non...3/13/201417611(글쓴이의 요청으로 삭제합니다.) [2]
1237(non...3/11/201417671(글쓴이의 요청으로 삭제합니다.) [2]
1236(non...3/11/201418524(글쓴이의 요청으로 삭제합니다.) [2]
1235(non...3/10/201417603(글쓴이의 요청으로 삭제합니다.) [2]
1234(non...3/10/201420752(글쓴이의 요청으로 삭제합니다.) [3]
1233(non...3/9/201418452(글쓴이의 요청으로 삭제합니다.) [4]
1232(non...3/8/201417366(글쓴이의 요청으로 삭제합니다.) [2]
1231(non...3/7/201418673(글쓴이의 요청으로 삭제합니다.) [9]
1230POCO3/7/201419009쓰레드 안에서 DependencyProperty get, set시 또 다른 스레드 오류.. [1]
1229(non...3/6/201419661(글쓴이의 요청으로 삭제합니다.) [11]
1228POCO3/6/201417695안녕하세요. 질문이 있습니다. [1]
1226김형진3/4/201427843안녕하세요 windows azure에 관해 질문했던 사람입니다. [2]
1224(non...3/3/201423198(글쓴이의 요청으로 삭제합니다.) [11]
1223sadf...3/3/201417741아래 질문에 답변 감사드립니다. 한가지 더 궁금한점이 있어 질문드립니다. [1]
1222(non...3/2/201418197(글쓴이의 요청으로 삭제합니다.) [4]
1221(non...3/1/201418608(글쓴이의 요청으로 삭제합니다.) [2]
1220Until2/28/201416903질문드립니다. [1]
1219이성환2/28/201416358string.Join()과 Enumerable.Aggregate()의 차이가 궁금합니다. [2]파일 다운로드1
1218김형진2/25/201418167안녕하세요. window azure에 대해서 질문이 있어서 문의 드립니다 [4]
1217(non...2/23/201418761(글쓴이의 요청으로 삭제합니다.) [1]
1215아리수2/20/201422206C# 공부하면서 WPF에 대한 질문. [2]
1214조광훈2/20/201420240IIS8 응용프로그램 풀 관련 질문 드립니다. [2]파일 다운로드1
1213김태훈2/17/201417399가상화 프로그램 질문입니다. [1]파일 다운로드1
1212조광훈2/13/201416184ISAPI 필터에서 커스텀 헤더 정보 추가 [1]파일 다운로드1
... 46  47  48  49  50  51  52  53  54  55  56  [57]  58  59  60  ...