Microsoft MVP성태의 닷넷 이야기
List<ArrarySegment<int>> 사용법 질문드립니다! [링크 복사], [링크+제목 복사],
조회: 13815
글쓴 사람
한예지 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)
5623한예지 donator3/15/202211069인터프리터 원리가 궁금합니다. [4]
5622김민아3/8/202211193const와 readonly의 명확한 차이가 이게 맞나요? [2]
5621장성욱3/8/202211274c# 로그 관련 질문 [1]
5620김민아3/7/202210894안녕하세요 비관리 객체를 반환하는 메소드 호출 시 궁금한 점이 있어서 질문드립니다 [2]
5619팡팡이3/3/202212700RSA 문의드립니다. [3]
5618김기헌3/2/202210803안녕하세요 생성자 옆에 this 키워드를 붙여 생성자를 여러 개 호출 시 질문드립니다 [2]
5617Edun2/25/202211450ArgumentOutOrRangeException에러 발생 [2]파일 다운로드1
5616csha...2/24/202210835readonly struct로 선언된 구조체를 특정 클래스에서 멤버변수로 가지는 경우 [1]
5615장성욱2/22/202214261SetThreadAffinityMask를 이용한 쓰레드 지정하는 방법에 대해 궁금합니다. [4]
5614민우2/22/202213484SSL 통신 문의 [6]
5613김인태2/22/202211761서버와 PC 간의 어플리케이션 성능 차이 [1]
5612팬입니다2/20/202210813Kastrel 서버 관련 [1]
5611차가워2/19/202210963stopWatch 늘어짐 문의 [3]
5610차가워2/18/202210816Stopwatch 늘어짐 문제 [1]
5609cs린이2/15/202211034c# 함수의 호출 방식에 대해 궁금합니다! [2]
5608지호2/10/202211873시작하세요 C# 8.0 중 제네릭타입의 IEnumerable [3]파일 다운로드1
5607이로운2/10/202210519안녕하세요. 궁금한게 있어서 질문드립니다. [1]
5605강성봉2/10/202210976TCP PSH flag 패킷 수신 에러 [1]
5604LW2/9/202211747VISUAL STUDIO 2019 ==> 2020 설치시 오류가 생겨서 문의드립니다. [3]
5603김진명2/9/202212888C# 10.0 출간은 언제쯤 계획하고 계신가요? [1]
5602신갑영2/8/202211331윈폼에 대해서 질문 드립니다. [1]
5601김인태2/4/202211459setup project 관련 [7]
5600itkim2/3/202213196윈도우 서버 계정 패스워드 인증 문의 [5]
5599레드골드2/3/202213610c#으로 ms word 제어 가능할까요? [6]
5598jaew...2/2/202211817Dictionary는 참조형식인가요?? [1]
5597재원2/2/202212322c# 9.0에 대한 내용을 받을 수 있나요? [1]
1  2  3  4  5  6  7  8  9  10  11  12  13  [14]  15  ...