본문 바로가기

Tip !!!/C# tip

배열 늘리기

Array.Resize( ref  배열이름 , 새로운 크기 );


using System;

namespace ConsoleApp2
{
    internal class Program
    {
        public struct Font
        {
            public string s;
            public short[] f;           
        }


        static void Main(string[] args)
        {
            Font[] font = new Font[1];     방 1칸
            font[0].s = "한";
            font[0].f = new short[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            Array.Resize(ref font, 2);     방 2칸
            Font f = new Font("국", new short[] { 0, 1, 2, 3 });
            font[1] = f;
            Console.WriteLine(font.Length);                               // 2
           foreach (short i in font[0].f)  Console.Write(i+" ");      // 0 1 2 3 4 5 6 7 8 9
            Console.WriteLine();
            foreach (short i in font[1].f ) Console.Write(i+" ");      // 0 1 2 3
            Console.WriteLine();
            f = new Font("국", new short[] { 0, 1, 2, 3, 100 });
            foreach (short i in font[1].f )        // 안 바뀌네요   참고그냥
                Console.Write(i + " ");                                               // 0 1 2 3


        }
    }
}

2
0 1 2 3 4 5 6 7 8 9
0 1 2 3
0 1 2 3 계속하려면 아무 키나 누르십시오 . . .