Microsoft MVP성태의 닷넷 이야기
List<ArrarySegment<int>> 사용법 질문드립니다! [링크 복사], [링크+제목 복사]
조회: 6315
글쓴 사람
한예지 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)
5618김기헌3/2/20224333안녕하세요 생성자 옆에 this 키워드를 붙여 생성자를 여러 개 호출 시 질문드립니다 [2]
5617Edun2/25/20224458ArgumentOutOrRangeException에러 발생 [2]파일 다운로드1
5616csha...2/24/20224357readonly struct로 선언된 구조체를 특정 클래스에서 멤버변수로 가지는 경우 [1]
5615장성욱2/22/20226542SetThreadAffinityMask를 이용한 쓰레드 지정하는 방법에 대해 궁금합니다. [4]
5614민우2/22/20225829SSL 통신 문의 [6]
5613김인태2/22/20224387서버와 PC 간의 어플리케이션 성능 차이 [1]
5612팬입니다2/20/20224191Kastrel 서버 관련 [1]
5611차가워2/19/20224425stopWatch 늘어짐 문의 [3]
5610차가워2/18/20224315Stopwatch 늘어짐 문제 [1]
5609cs린이2/15/20224649c# 함수의 호출 방식에 대해 궁금합니다! [2]
5608지호2/10/20225158시작하세요 C# 8.0 중 제네릭타입의 IEnumerable [3]파일 다운로드1
5607이로운2/10/20224397안녕하세요. 궁금한게 있어서 질문드립니다. [1]
5605강성봉2/10/20224425TCP PSH flag 패킷 수신 에러 [1]
5604LW2/9/20224561VISUAL STUDIO 2019 ==> 2020 설치시 오류가 생겨서 문의드립니다. [3]
5603김진명2/9/20225838C# 10.0 출간은 언제쯤 계획하고 계신가요? [1]
5602신갑영2/8/20224639윈폼에 대해서 질문 드립니다. [1]
5601김인태2/4/20224881setup project 관련 [7]
5600itkim2/3/20225692윈도우 서버 계정 패스워드 인증 문의 [5]
5599레드골드2/3/20226165c#으로 ms word 제어 가능할까요? [6]
5598jaew...2/2/20224861Dictionary는 참조형식인가요?? [1]
5597재원2/2/20225204c# 9.0에 대한 내용을 받을 수 있나요? [1]
5596kss1/26/20224929듀얼 모니터 환경에서 wpf 프로그램 크기 변경 [2]
5594mira...1/25/20224578안녕하세요 try~catch 와 SuspendLayout~ResumeLayout 간 호출 문의드립니다! [2]
5593C#스터디1/12/20225483TaskAwaiter 구현 질문 입니다. [1]
5591유지킴12/24/20215109outofmemory in 32bit [2]파일 다운로드1
5590kss12/23/20214563포인터 메모리 에러 [1]
1  2  3  4  5  6  7  8  9  10  11  12  [13]  14  15  ...