<aside> 💡 구조체 (Structure Types)란?
**데이터 보관 관점 비교
- 배열(Array) 변수확장 하나의 이름으로 하나의 데이터 형식을 여러 개 보관
- 구조체(Struct) 변수/배열의 확장 하나의 이름으로 여러 개의 데이터 형식을 하나/여러 개 보관
</aside>
*****구조체 선언 및 사용이란?
public struct Employee
{
public string Name;
public int Age;
}**
public string Name;
public int Kor;
public int Eng;
public int Tot;
public int Avg;
public int Graph;
//public int x; // 공용
//public int y;
//private int z; // 전용 ( 구조체에서만 사용가능한..)
}
static void Main(string[] args)
{
Score[] scores = new Score[3]; //3명학생
scores[0].Name = "홍길동";
scores[0].Kor = 100;
scores[0].Eng = 90;
scores[1].Name = "백두산";
scores[1].Kor = 90;
scores[1].Eng = 80;
scores[2].Name = "임꺽정";
scores[2].Kor = 90;
scores[2].Eng = 70;
for (int i = 0; i < 3; i++)
{
scores[i].Tot = scores[i].Kor + scores[i].Eng;
scores[i].Avg = scores[i].Tot / 2;
scores[i].Graph = scores[i].Avg / 5; //평균값을 5로 나눔. .
}
Console.WriteLine("이름\t 총점\t 평균\t 막대 그래프");
for (int i = 0; i < 3; i++)
{
Console.Write(
$"{scores[i].Name}\t {scores[i].Kor}\t {scores[i].Eng}\t");
for (int j = 0; j < scores[i].Graph; j++)
{
Console.Write("★");
}
Console.WriteLine();
}
**DateTime.Now - (new DateTime(2020,1,1))
[180.07:17:11.6878863]
TimeSpan ts = (DateTime.Now - (new DateTime(2020,1,1)))
-> TimeSpan 구초제로 날짜의 대한 차이를 ts 변수에 담을 수 있음.
ts.TotalDays
하게되면 총 180.30398335418749 지났구나 알 수 있음!
(DateTime.Now - (new DateTime(2020,1,1))).ToTavlDays
180.....
Math.Ceiling((DateTime.Now - (new DateTime(2020,1,1))).ToTavlDays)
181 <- 하루 올림.
var days = Math.Ceiling((DateTime.Now - (new DateTime(2020,1,1))).ToTavlDays)
days
181**
$$ 날짜 부분은 DateTim.Now 구조체만 잘 사용하면 됨!
$$
static void Main(string[] args)
{
// 현재 시간 출력 DateTime 구조체
Console.WriteLine(GetDateTimeFromYear1yHourNumber(1)); //2018-1-1 00
Console.WriteLine(GetDateTimeFromYear1yHourNumber(8760/2));
Console.WriteLine(GetDateTimeFromYear1yHourNumber(8760)); //2018-12-31 00
Console.WriteLine($"현재시간 : {DateTime.Now}");
// 년 월 일 시 분 초 출력
Console.WriteLine(DateTime.Now.Year);
Console.WriteLine(DateTime.Now.Month);
Console.WriteLine(DateTime.Now.Day);
Console.WriteLine(DateTime.Now.Hour);
Console.WriteLine(DateTime.Now.Minute);
Console.WriteLine(DateTime.Now.Second);
Console.WriteLine(DateTime.Now.Millisecond);
// DateTime 형식의 변수 선언
DateTime now = DateTime.Now;
Console.WriteLine(now.Date);
Console.WriteLine(now.ToLongTimeString());
// 시간차 D-Day 구하기 : TimeSpan 구조체 사용
TimeSpan dday = Convert.ToDateTime("2022-12-25") - DateTime.Now;
Console.WriteLine($"{DateTime.Now.Year}년도 크리스마스는 {(int)dday.TotalDays}남았습니다.");
}
static DateTime GetDateTimeFromYear1yHourNumber(int number)
{
return (new DateTime(2018, 1, 1, 0, 0, 0)).AddHours(--number);
}
**Char.ToUpper('a') -> 소문자를 대문자로 바뀌다.
Char.IsWhiteSpace(' ') -> 공백이냐?
Char.IsDigit('1') -> 숫자냐?
Char.IsLetterOrDigit(' ') -> 숫자 또는 문자냐? 난 공백이다 그럼 false~
Char. 나오는 많은 메서드들이 존재하다! 캐릭터도 구조체다! 많이는 사용안함!**