nullable

7호선개발자·2020년 6월 24일
0

using System;
using System.Collections.Generic;

namespace project
{

class Program
{



    static int Find()
    {
        return 0;
    }

    class Monster
    {
        public int Id { get; set; }
    }

    static void Main(string[] args)
    {

        // Nullable -> Null + able

        int? number = null;

        int c = (number != null) ? number.Value : 0;
        int b = number ?? 0;
        System.Console.WriteLine(b);


        Monster monster = null;

        if (monster != null)
        {
            int monsterId = monster.Id;
        }

        int? id = monster?.Id;

        if (monster == null)
        {
            id = null;
        }
        else
        {
            id = monster.Id;
        }

    }

}

}

profile
안녕하세요

0개의 댓글