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

선생님 안녕하세요!
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]);
            }
        }
    }
[손님]

1  2  3  4  5  6  7  8  9  10  11  12  13  14  [15]  ...
NoWriterDateCnt.TitleFile(s)
5492한예지5/5/20212496FromCurrentSynchronizationContext 관련 코드 질문있습니다! [2]
5491조우성5/4/20215752WinForm과 WPF의 성능차이 비교한 자료가 있을까요? [4]
5490한예지5/3/20212536UI 스레드의 Invoke 질문있습니다. [4]
5489저누4/28/20212916시작하세요 C# 9.0, 225페이지 구조체 관련 질문드립니다. [2]
5488종범4/27/20213069C# 비동기 함수 async, await 와 Task의 관계에 대해 질문 드립니다. [6]
5487진우4/27/20213032C# 엑셀 자동화 성능 향상 문의 [2]
5486지나...4/26/20212865닷넷 구현 코드 관련 질문 [2]
5485이재원4/17/20212883교재 315페이지 내용 질문 [3]
5484Sy...4/16/20215363윈폼 기반의 응용프로그램 dll 참조와 32,64bit 빌드 관련 문의 [4]
5483한예지4/15/20212558익명 형식과 var 관계 질문 있습니다. [2]
5482질문4/13/20213933WPF를 위한 MVVM toolkit 선택과 관련한 문의드립니다. [4]
5480한예지4/5/20213402GetHashCode 질문있습니다! [2]
5479한예지4/4/20213196Equals를 닷넷에서 어떻게 구현했는지 보고 싶을 떄는 어떻게 해야 될까요? [2]
5478갑자...3/23/20215083C# Winform에서 TextBox없이 입력 받을 수 있나요? [7]
5477달팽이3/18/20212951c# 도형을 그린후 편집하는 방법이 궁금합니다. [2]파일 다운로드1
5475di...3/2/20213479POH가 .NET 5에 추가된 것으로 알고 있습니다. POH가 유용한 경우는 어떤 경우가 있을까요? [1]
5474Sy...2/26/20213034사용자 지정 컨트롤 생성시 Invalidate, Update, Refresh의 차이점 [2]
5473한예지2/25/20212954디자인 타임이 뭔지 궁금합니다!! [5]
5472di...2/24/20213320등록하지 않고 ocx를 사용하는 `키움`관련 포스팅을 따라가다 질문드립니다. [9]
5471남산2/21/20212972MarshalDirectiveException 에 대한 질문입니다. [1]
5470한예지2/7/20213019yield 질문있습니다!! [2]
5469유호성2/6/20212537Parallel + Task.Run 동시 실행 환경에서 간헐적으로 Task.Run()에서 null이 리턴됩니다. [3]파일 다운로드1
5467he...2/4/20212787실행 환경에 따른 Thread.Sleep 딜레이 차이 질문 [8]
5466pr1/29/20212749c# winform load시 작업표시줄에 뜨지 않는 현상을 겪으신적이 있으신가요? [4]파일 다운로드1
5465영귤1/28/20212732두 번째 await 부터는 스레드 개수만 늘어나는 것이 아닌가요 [1]
5464민우1/26/20212653C# 빌드시 코드 치환되는걸 확인하는 방법 문의 [2]
1  2  3  4  5  6  7  8  9  10  11  12  13  14  [15]  ...