보관함

csharp 몇몇 코드 단순화

in 매개 변수

// 여기서의 in은 ref readonly처럼 작동함 함수 call시에는 in을 쓰거나 말거나 동일
void PrintDate(in DateTime date)
{
    Console.WriteLine(date);
}

null 관련 연산자

// 오래전
instance = instance == null ? value : instance;

// 기존
instance = instance ?? value;

// 현재
instance ??= value;

Auto Property

// C# 6.0 Auto property
public string Name { get; set; } = "Karu";

Index 연산

// C# 8.0 인덱스 연산
string str = "Rolling Ress";
var last = str[^1]; // 's'
var sub = str[0..4]; // "Roll", 구간은 [0, 4)

 

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

  

  

  

이 사이트는 Akismet을 사용하여 스팸을 줄입니다. 댓글 데이터가 어떻게 처리되는지 알아보세요.