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

... 61  62  63  64  65  [66]  67  68  69  70  71  72  73  74  75  ...
NoWriterDateCnt.TitleFile(s)
958꼭지3/3/201121778Supporting compressed request in WCF 3.5 [5]
957임동찬2/21/201122214WCF channel faulted 관련 [2]
956윤용한2/18/201125804WaitHandle.WaitOne 과 Stopwatch에 관한 질문 [3]
955최광욱2/17/201122098TFS 에서 소스 영구 제거 방법 [1]
954한장우2/16/201119820atl activeX 질문이요~ [1]
952박용운2/16/201120807IE8.0에서 BHO [1]
953박용운2/16/201120606    답변글 [답변]: IE8.0에서 BHO
951임동찬2/11/201121155WCF Service Reference [1]
950이성환2/9/201122861Windows application 프로젝트를 참조 했을 때 생성되는 실행파일을 직접 실행 불가능하도록 하고 싶습니다. [6]파일 다운로드1
947김순조1/24/201121046.NET based Com에서 Native ActiveX로 이벤트 보내기?? [2]파일 다운로드1
943김기룡1/3/201124487닷넷 에러시 조치사항관련... [2]
942김기룡12/27/201019525Thread 안정성 관련 문의 드립니다. [2]
941최광욱12/20/201019343정성태님 올리신 글중에 [1]
940최광욱12/20/201021301Assembly Unloading 관련해서 [2]
939최광욱12/20/201019330IIS 로그 읽기 [1]
938날쌘돌이12/14/201021139자바로 asp.net 인증하기 [3]
935김기룡12/13/201031549c#에서 c++로 개발된 dll에 byte[] 전달 관련하여 문의 드립니다. [6]
934임동찬12/7/201018765System.Reflection.Assembly.GetTypes() 메서드에 대해 [1]
929김준호12/2/201018607안녕하세요 비주얼베이직 2005 닷넷 관련 문의입니다 [1]
928김준호11/30/201018962안녕하세요 비주얼베이직 2005 닷넷 관련 문의입니다 [1]파일 다운로드1
927임동찬11/30/201020769Windows\\Temp 폴더의 이름모를 .tmp 파일들에 대해서 [1]
926이승규11/26/201040766IP접속 시도시 ORA-12504 에러 [1]
925임동찬11/11/201018060다른 프로그램의 컨트롤 건드려보기_추가질문(2) [1]
924임동찬11/10/201018637다른 프로그램의 컨트롤 건드려보기_추가질문 [1]
923임동찬11/9/201021362다른 프로그램의 컨트롤 건드려보기 [1]
922박태근11/2/201020028html5의 shape파일 관련 [1]파일 다운로드1
... 61  62  63  64  65  [66]  67  68  69  70  71  72  73  74  75  ...