[C#] 배열
by #독개#/* 배열은 1차원, 2차원만 쓰인다 보면된다. 객체지향에서 쓰는 사람에 따라 엄청 편하게 차이난다
* 다차원배열,가변배열 등등 있는데 그런거 실전에서 0프로 쓴다 */
namespace 배열
{
internal class Program
{
static void Main(string[] args)
{
int[] arr = { 1, 2 }; //원래 int[] arr = new int[] { 1, 2 }; 생략가능
int[,] arr2 = { { 1, 2 }, { 2, 3 } }; //2차원배열
Console.WriteLine(arr[0]);
Console.WriteLine(arr2[0,1]);
/*3차원4차원 다가능 하지만 위의 방식은 클래스를 메인으로 쓰는 C#에선 비효율적이다*/
Student[] students = new Student[2];
students[0] = new Student("홍길동",2);
students[1] = new Student("호랑이",1);
Console.WriteLine("이름: " + students[0].Name + " 반: " + students[0].StClass);
}
}
}
class Student
{
public string Name { get; set; }
public int StClass { get; set; }
public Student(string _name, int _stclass)
{
this.Name = _name;
this.StClass = _stclass;
}
}

'🔥 프로그래밍 학습 > C#' 카테고리의 다른 글
| [C#] For문 실습#1 구구단 (0) | 2022.11.24 |
|---|---|
| [C#] 제어문 (0) | 2022.11.22 |
| [C#] 접근제한자 (0) | 2022.11.22 |
| [C#] Static 클래스 / 프로그램의 시작 (0) | 2022.11.22 |
| [C#] 속성(Property) (0) | 2022.11.21 |
블로그의 정보
독한 개발자
#독개#