App Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study07
{
class App
{
//생성자
public App()
{
Console.WriteLine("App 생성자");
Console.WriteLine();
Student[] students = new Student[5];
students[0] = new Student("학생0", 00000, 50);
//Student student0 = new Student();
//student0.id = 00000;
//student0.name = "학생0";
//student0.score = 50;
students[1] = new Student("학생1", 00001, 80);
students[2] = new Student("학생2", 00002, 100);
students[3] = new Student("학생3", 00003, 60);
students[4] = new Student("학생4", 00004, 90);
//null 체크!
for(int i = 0; i < students.Length; i++)
{
if (students[i] != null)
Console.WriteLine("이름: {0}, 학번: {1}, 점수: {2}", students[i].name, students[i].id, students[i].score);
}
}
}
}
Student Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study07
{
class Student
{
public string name;
public int id;
public int score;
//생성자
public Student(string name, int id, int score)
{
this.name = name;
this.id = id;
this.score = score;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study07
{
class Program
{
static void Main(string[] args)
{
new App();
}
}
}
실행 결과
'C# > 수업내용' 카테고리의 다른 글
[C# 7일차] 배열의 최대값과 최소값 (0) | 2023.01.09 |
---|---|
[C# 7일차] 배열과 input (0) | 2023.01.09 |
[C# 7일차] 배열 복습 (0) | 2023.01.09 |
[C# 6일차] 배열을 이용한 Inventory 저장, 찾기, 삭제 (0) | 2023.01.08 |
[C# 6일차] 배열 (0) | 2023.01.06 |