Microsoft MVP성태의 닷넷 이야기
List<ArrarySegment<int>> 사용법 질문드립니다! [링크 복사], [링크+제목 복사],
조회: 6362
글쓴 사람
한예지 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)
5485이재원4/17/20216290교재 315페이지 내용 질문 [3]
5484Syong4/16/20219851윈폼 기반의 응용프로그램 dll 참조와 32,64bit 빌드 관련 문의 [4]
5483한예지 donator4/15/20215346익명 형식과 var 관계 질문 있습니다. [2]
5482질문4/13/20217138WPF를 위한 MVVM toolkit 선택과 관련한 문의드립니다. [4]
5480한예지 donator4/5/20217459GetHashCode 질문있습니다! [2]
5479한예지 donator4/4/20216524Equals를 닷넷에서 어떻게 구현했는지 보고 싶을 떄는 어떻게 해야 될까요? [2]
5478갑자기C#3/23/20218971C# Winform에서 TextBox없이 입력 받을 수 있나요? [7]
5477달팽이3/18/20215964c# 도형을 그린후 편집하는 방법이 궁금합니다. [2]파일 다운로드1
5475dimo...3/2/20216983POH가 .NET 5에 추가된 것으로 알고 있습니다. POH가 유용한 경우는 어떤 경우가 있을까요? [1]
5474Syong2/26/20216523사용자 지정 컨트롤 생성시 Invalidate, Update, Refresh의 차이점 [2]
5473한예지 donator2/25/20216402디자인 타임이 뭔지 궁금합니다!! [5]
5472dimo...2/24/20217181등록하지 않고 ocx를 사용하는 `키움`관련 포스팅을 따라가다 질문드립니다. [9]
5471남산2/21/20215822MarshalDirectiveException 에 대한 질문입니다. [1]
5470한예지 donator2/7/20215748yield 질문있습니다!! [2]
5469유호성2/6/20215309Parallel + Task.Run 동시 실행 환경에서 간헐적으로 Task.Run()에서 null이 리턴됩니다. [3]파일 다운로드1
5467hero...2/4/20215702실행 환경에 따른 Thread.Sleep 딜레이 차이 질문 [8]
5466pr1/29/20215574c# winform load시 작업표시줄에 뜨지 않는 현상을 겪으신적이 있으신가요? [4]파일 다운로드1
5465영귤1/28/20215933두 번째 await 부터는 스레드 개수만 늘어나는 것이 아닌가요 [1]
5464민우1/26/20216205C# 빌드시 코드 치환되는걸 확인하는 방법 문의 [2]
5463한예지 donator1/24/20216960Parameters.AddWithValue 와 Parameters.Add 의 차이점이 궁금합니다. [2]
5462C#초보1/22/20217350사용자 정의 메시지 전달이 가능한가요? [2]
5461한예지 donator1/22/20216749AsEnumerable() 메서드 질문 있습니다! [2]
5459한예지 donator1/21/20216085typeof와 GetType의 차이점 질문있습니다. [2]
5458진우1/20/20216967C# DataTable 에 SQL 쿼리문을 실행하는 방법 문의 (LINQ 사용하지 않고) [6]
5456성민1/17/202173839.0 출간 계획이 있으신가요? [2]
5455한예지 donator1/16/20216408교재 194페이지 콜백메서드 질문 있습니다! [5]
... 16  17  [18]  19  20  21  22  23  24  25  26  27  28  29  30  ...