목록언어/C# (31)
Machineboy空
DateTimeimmutable(불변의) object that contains both date and time information.DateTime 특징한 번 DateTime이 생성되면 값이 절대 변하지 않는다. DateTime을 modify하려고 하면 return new DateTimetextual representaion은 dependent on the cultureen-US(America English) : "3/28/19 2:30:59 PM"DateTime.Parse() : string을 DateTime으로 변환using System;static class Appointment{ // string -> DateTime public static DateTime Schedule(string a..
Class의 개념The primary object-oriented construct기초적인 객체 지향 구조(?) a combination of data(field) and behavior(methods).fields and methods of a class = members Class의 Member 접근자Access to members can be restricted through access modifierpublic : member can be accessed by any codeprivate : member can only be accessed by code in the same classclass Car{ // public field in PascalCase public int Weight; ..
완전 기초를 다시 다지고 가자.조건문 구성할 때 switch문이 적절한 케이스였음에도 바로 생각나지 않아서 정리한다.If문특정 조건에 따라 코드를 실행할지 말지 결정할 수 있는 문법if( 조건부 ) { 동작부 }if( 기온이 0도 이하라면 ) { 물이 업니다. }else { 물이 얼지 않습니다. } else if문두 가지 이상의 옵션이 필요할 때if ( 기온이 0도 이하라면 ) { 물이 업니다. }else if ( 기온이 100도 미만이라면 ) { 물이 얼지도 끓지도 않습니다. }else { 물이 끓습니다. }switch 문어떤 값을 입력했는지에 따라 다르게 동작하는 문법case가 동등하게 선택지로 주어지는 느낌switch ( 비교할 값 ){ case 조건값1: 동작부분; break;..

컬렉션(Collection)이란?data structures that can hold zero or more elements are known as collections0개 혹은 더 많은 요소를 가질 수 있는 데이터 구조배열(Array) 이란 ? + 특징컬렉션 중 하나fixed size, elements must all be of the same type (모든 요소가 같은 타입, 고정된 크기의 공간)retrieved from using an index start from 0 (0부터 시작하는 인덱스로 검색 가능)reference type// size가 2인 배열 선언int[] twoInts = new int[2];// 요소에 값 할당twoInts[1] = 8;// 인덱스로 검색twoInts[1] == ..
Random Seed란?컴퓨터 프로그램에서 발생하는 무작위 수는 사실 엄격한 의미의 무작위 숫가 아니다.특정한 시작 숫자(seed)를 정해주면 컴퓨터가 정해진 알고리즘에 의해 마치 난수처럼 보이는 수열을 생성한다.seed 값이 고정될 경우, 생성되는 랜덤 값이 동일해진다. https://machineboy0.tistory.com/20 예제 코드using System;public class Player{ // 난수 생성기 생성 private Random random = new Random(); // Int 형 난수 : 1 ~ 18 public int RollDie() { // 파라미터 a이상 b 미만 return random.Next(1,19); } ..
Nullabsence of a value.C# 8.0 이전// 참조 타입: null 가능string nullableReferenceType = "hello";nullableReferenceType = null;// 값 타입 : null이 될 수 있음을 명시해줘야 했다.int nonNullableValueType = 5;nonNullableValueType = null; // compile error: not nullableint? nullableValueType = 5;nullableValueType = null;// null값에 접근하려고 하면 NullReferenceException 에러string sentence = null;sentence.Lenth; // NullReferenceExceptio..
문자열 분할(Split()), 문자열 변형(공백 제거, Trim())형식[LEVEL]: 입력[Error]: Invalid operation출력MESSAGE 부분만조건앞, 뒤 공백은 제거 되어야 한다.// : 기준 문자열 분할string[] strs = logLine.Split(": ");// 공백 제거string message = strs[1].Trim(); *Split()https://learn.microsoft.com/ko-kr/dotnet/api/system.string.split?view=net-8.0 String.Split 메서드 (System)지정된 문자열 또는 유니코드 문자 배열의 요소로 구분된 이 인스턴스의 부분 문자열을 포함하는 문자열 배열을 반환합니다.learn.microsoft.co..