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

1  2  3  4  5  6  [7]  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
5808근우1/30/202310740WPF 에서 UserControl 과 ControlTemplate 의 차이점은 무엇인가요? [6]
5807궁금맨1/28/202313054C# 10 책에 나온 예제의 결과가 제 컴에서는 좀 달라서요. 이유가 궁금합니다. [1]
5806스레드1/25/202310304총정리 - 다양한 스레드들 [초안] [1]파일 다운로드1
5805어웨이트1/25/202310046Taskcontinuewith vs Async/Await [2]파일 다운로드1
5804나이많은...1/25/20239885MS의 Dependency Injection(DI)에 AddSingleton으로 등록된 객체의 Event 등록후 사용시 앱 종료시 별도로 Event를 해지해야 하나요? [2]
5803dssc...1/24/202310260드라이브 문자를 통해서 물리 디스크 명칭을 알아내고 싶습니다. [1]
5802모바일앱1/22/202310746XAMARINE vs Android Studio [7]
5801블루투스1/19/202311431WPF 은행지폐계수기 개조 후 결과값 서버 전송 [2]파일 다운로드1
5800김민아1/19/202311569안녕하세요 가비지 컬렉터 동작 원리 중 궁금한점이 있습니다 [5]
5799guest1/19/202310878C# 공유폴더 내 Acess 디비 공유 [2]
5798kss1/19/202310065책 오탈인가요? [1]
5797이거비버1/19/20239865C# 공부 이후 MS 프레임워크.. 어느것을 공부해야할까요? 너무 많아서 정신이 없네요 [5]
5796guest1/19/20239649해킹 test [3]
5795동기1/18/20238984동기 스레드와 메서드와 While [2]
5794박규동1/18/20239181.net publish 할때마다 runtimeconfig 값이 바뀌는 현상 [1]
5793후후훗1/18/20239653.NET Core 에서 사용중인 함수 후킹 방법 [2]
5792Will...1/18/20239535소스코드 Log Write 기능을 리스트업 질문 [9]
5791PLC1/16/202310177C# - 실시간 5개 룸 모니터링 [15]
5790집으로 ...1/13/20239810[UI 멈춤 현상]deadlock 관련 글을 보고 혹시나 하고 문의 드립니다. [4]
5789guest1/10/20239709스레드와 Async Task [2]파일 다운로드1
5788kr11/10/202310154C# 에서 제공하는 컬렉션들의 차이점이 궁금합니다. [3]
5787stack1/10/202310042STACKOVERFLOW [1]
5786Dev ...1/9/202311861익명 클래스 말고 익명 구조체는 불가능한걸까요? [4]
5785음성인식1/8/202311558음성인식 System.Speech - 문법에 사용된 언어가 음성 인식기의 언어와 일치하지 않습니다. [2]
5784MS워드1/8/202310817MS워드에서 ctrl Z는 클립보드를 이용하나요? 아니면 참조자 이용하나요? [7]
5783구직자1/7/202310095C#개발자 구인광고와 초급개발자 [3]파일 다운로드1
1  2  3  4  5  6  [7]  8  9  10  11  12  13  14  15  ...