개발/C#
# AS (형 변환) / IS (타입 확인) 키워드
노마드
2021. 1. 25. 07:55
AS 키워드는 형변환하는데 사용 되며, IS 키워드는 타입을 확인하는데에 사용 된다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp6
{
class Program
{
static void Main(string[] args)
{
Car car = new Car();
new Program().AsTest(car);
Console.ReadLine();
}
void AsTest(object obj)
{
Car car = obj as Car;
bool yes = obj is Car;
Console.WriteLine(yes);
}
}
class Car
{
}
}