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

... 31  [32]  33  34  35  36  37  38  39  40  41  42  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
5072엔벌잉10/24/20188160C# textbox, button질문입니다! [4]파일 다운로드1
5071엔벌잉10/23/20188549C#윈도우폼 질문입니다!! [2]
5070진우10/17/20188502Visual Studio 서비스팩과 업데이트 차이 문의 [2]
5069감자10/12/20189263빌드 구성을 재설정하는 방법이 있을까요? [1]파일 다운로드1
5068누오10/10/20188036ASP Core 2.0 에서 dll안에 있는 뷰 읽어들이는 방법? [1]
5067김정민10/5/20188027다른 윈도우가 깨지는 현상을 막을 수 있을까요 [3]
5066로니브10/4/20188826ASP.NET MVC에서 View 파일 숨기는법? 보안처리 하는법? 관련 질문.. [1]
5065키모10/1/201810041문자 질문입니다. [3]
5064로니브10/1/20189375클래스 라이브러리에서 .cshtml파일을 추가하는 방법은 없나요? [3]
5063진우9/28/20188424ADO.net 과 Entity Framework 차이 문의 [2]
5062테스트9/27/20188937C# import file 의 구조체 배열 선언 및 호출에 대해 문의. [3]
5061안녕하세요9/13/20188929c# 프로그래밍 관련 문의 [1]
5060임민재9/8/20188422c# install 파일 생성 시 문제가 발생하였습니다 [1]파일 다운로드1
50599/7/20188058Winform TextBox 포커스 유지하는 방법 질문 [파일첨부] [1]파일 다운로드1
50589/5/201811469Winform TextBox 포커스 유지하는 방법 질문 [3]
5056박종윤8/30/201810797c# dll을 C++에서 사용 시 event 호출 [4]파일 다운로드1
5055초보자8/29/20189469asp.net 에서 다른 서버의 iis를 stop하는 batch file을 실행시키는데 동작하지 않습니다. [5]
5054사도신8/29/20188163[wpf] textbox insert overite 모드시에 [4]파일 다운로드1
5053엿장수8/26/20187514directshow filter 에서의 IMediaSample 의 시간에대한질문입니다 [1]
5052오명현8/26/20188409Tcp소켓 실습 Exeption 도와주세요! [4]파일 다운로드1
5049오명현8/23/20187771책 477페이지 내용 중 이해가 안가는 부분이 있어 질문드립니다. [1]
5048오명현8/23/20187447포트 관련 질문 하나더 있습니다. [1]
5047오명현8/22/20188126포트가 없을 경우를 가정한 내용에 대해 질문이 있습니다. 책468p. [1]
5046엿장수8/22/20188021다이렉트쇼 필터 추가하는데 [2]
5045임도진8/22/20188741c# opencv dll파일 로드 질문 [3]파일 다운로드1
5044엿장수8/20/20188446graphedit 에 등록되어있는 필터를 가져와서 사용하는방법을 알고싶습니다 [2]
... 31  [32]  33  34  35  36  37  38  39  40  41  42  43  44  45  ...