KO CSharp Operator Null Forgiving - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki

ะฃะบั€ะฐั—ะฝััŒะบะฐ ยท ะ ัƒััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซ”ไธญๆ–‡ ยท ๆ—ฅๆœฌ่ชž ยท ํ•œ๊ตญ์–ด

Null ํ—ˆ์šฉ ๊ฒฝ๊ณ  ์–ต์ œ

ํ•ธ๋“œ๋ถ C# ยท ์‹ค์šฉ ๊ฐ€์ด๋“œ

ํ‘œํ˜„์‹์ด ๋น„null๋กœ ์ฒ˜๋ฆฌ๋จ์„ null ํ—ˆ์šฉ ๋ถ„์„์— ์•Œ๋ฆฝ๋‹ˆ๋‹ค. ๊ฐ’์„ ํ™•์ธํ•˜์ง€ ์•Š์œผ๋ฉฐ NullReferenceException๋กœ๋ถ€ํ„ฐ ๋ณดํ˜ธํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

๊ฐ„๋‹จํ•œ ์˜ˆ์ œ (Example.cs)

์ด ์˜ˆ์ œ๋ฅผ Example.cs๋กœ ๋”ฐ๋กœ ์ €์žฅํ•˜๊ณ  ์ด ํŽ˜์ด์ง€์˜ ๋‹ค๋ฅธ ์˜ˆ์ œ์™€ ๋…๋ฆฝ์ ์œผ๋กœ ์‹คํ–‰ํ•˜์„ธ์š”.

Example.cs:

// PROJECT-EXAMPLE
string? name = "ore";
System.Console.WriteLine(name!.Length);

๊ฒฐ๊ณผ:

3

ํ†ต์‚ฌ๋ก 

possiblyNull!.Member

์˜ˆ์‹œ 1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

public static class Program
{
    public static async Task Main(string[] args)
    {
        string? text = "ore";
        Console.WriteLine(text!.Length);
    }
}

์˜ˆ์‹œ 2

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

public static class Program
{
    public static async Task Main(string[] args)
    {
        Dictionary<string, string> values = new() { ["name"] = "Archer" };
        values.TryGetValue("name", out string? name);
        Console.WriteLine(name!.ToUpperInvariant());
    }
}

๊ณต์‹ ์ถœ์ฒ˜: Microsoft ํ•™์Šต.