Microsoft MVP성태의 닷넷 이야기
List<ArrarySegment<int>> 사용법 질문드립니다! [링크 복사], [링크+제목 복사],
조회: 15598
글쓴 사람
한예지 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)
3672Sung...12/23/201519819global::System.Diagnostics.Debugger.Break();가 노랗게 표시될시 [2]
3671이상준12/22/201524940한글 키보드 입력에 대해서 질문이 있습니다. [3]
3670Sung...12/18/201520127UWP 주기적으로 신호를 보내고 클라이언트에서 신호가 오면 받는 프로그램을 하려고 합니다. [5]
3669다비드12/18/201519204인터넷 임시파일 삭제 관련 질문. [1]
3668김치사발면12/16/201518585템플릿이 자꾸 초기화? 되버리네요 [1]
3667김치사발면12/15/201518219템플릿 설정 추가 질문 [1]파일 다운로드1
3666노태현12/15/201517517사용자별로 권한을 주고 볼 수 있는 데이터를 제한하려면 어떤 방법으로 접근하는게 좋을까요? [2]
3665김치사발면12/14/201520805C# 템플릿 설정이 이상해요ㅜㅜ [3]파일 다운로드1
3664KuLu12/10/201517481멀정하던 사이트 중 일부메뉴가 응답없음이 되어버립니다. [3]
3663Sung...12/10/201519568UWP 서버 프로그래밍 작업 중 [5]
3662Sung...12/9/201519094uwp앱에서 접속한 클라이언트 주소값을 받아서 표시하고 싶은데 어떤 메소드를 써야 할까요? [7]
3661김무진12/9/201518942Oracle 환경에서 데이터를 조회할때 한글이 ? 이렇게 표시가됩니다. [1]
3660질문자12/7/201521093OpenFileDialog 호출시 hang걸리는 문제 [4]
3659Sung...12/4/201520918UWP 앱에서 textBox로 클라에서 받은 값을 나타내고 싶은데 안되고 있습니다. [5]
3658강준12/3/201519568Visual Studio (Xamarin) vs Eclipse [2]
3656DEVY...12/1/201519349MasterPageFile 사용시 다국어 처리 질문입니다. [1]
3653DEVY...11/26/201521327ds:Signature 질문입니다. [7]
3654윤용한11/27/201521373    답변글 [답변]: ds:Signature 질문입니다. [3]
3657윤용한12/1/201522808    답변글 [답변]: ds:Signature 질문입니다. [1]
3651노태현11/20/201553881MariaDB - ASP.NET오류의 원인조차 못 찾고 있습니다.. [2]파일 다운로드2
3652노태현11/20/201521117    답변글 [답변]: MariaDB - ASP.NET오류의 원인조차 못 찾고 있습니다.. [3]
3649kokon11/17/201520530예제 파일 실행이 안 되네요 [5]
3647Sang...11/15/201518454Part 3 목차? [5]
3646힘찬도약11/13/201524193c# mscorlib System.IO IOException [8]파일 다운로드2
3644힘찬도약11/11/201522935c# user.config파일 [2]
3645spow...11/13/201519383    답변글 [답변]: c# user.config파일 - Json.NET을 이용한 설정파일 처리 [1]파일 다운로드1
... 46  47  [48]  49  50  51  52  53  54  55  56  57  58  59  60  ...