๐ง ๋จํญ ์ฐ์ฐ์
โถ +,-, !, ~, ++, -- ๋ฑ
โถ!์ boolํ์๋ง ์ฌ์ฉ
๐ง์ฐ์ ์ฐ์ฐ์
โถ *, /, %, -, +
โถstirng์์ +๋ ๋ฌธ์์ด ์ฐ๊ฒฐ
์ ์/๋ถ๋ + "๋ฌธ์์ด" ="๋ฌธ์์ด"
๐ง ์ํํธ(shift) ์ฐ์ฐ์์ ๊ด๊ณ ์ฐ์ฐ์
โถ <<, >>, >=,<=, >,>,==, !=
โถ ๊ด๊ณ ์ฐ์ฐ์์ ๊ฒฐ๊ณผ๋ true, false
๐ง is์ฐ์ฐ์
โถํ์ ํธํ์ ์กฐ์ฌํ๋ ์ฐ์ฐ์
โถ ํ์
- '๋ณ์' is 'ํด๋์คํ' or '๋ฐ์ดํฐํ'
- A is B
- ๊ฒฐ๊ณผ๋ true false
โถ ๋ฐ์ฑ/์ธ๋ฐ์ฑ ๋ณํ, ์ฐธ์กฐ ๋ณํ์์ ์ฌ์ฉ
namespace ConsoleApp4
{
class Program
{
static void Main(string[] args)
{
int nValue = 10;
if(nValue is float)
{
Console.WriteLine("ํธํ๋จ");
}
else
{
Console.WriteLine("ํธํ ์๋จ");
}
Object obj = nValue; //๋ฐ์ฑ
if(obj is int)
{
Console.WriteLine("ํธํ๋จ");
}
else
{
Console.WriteLine("ํธํ ์๋จ");
}
}
}
}
๐ง as ์ฐ์ฐ์
โถ์ญํ
- ํ๋ณํ๊ณผ ๋ณํ ์กฐ์ฌ (๋ณํ ์๋๋ฉด null, ๋๋ฉด ๋ณํ๋ ๊ฐ์ ์ค)
- ์บ์คํธ ์ฐ์ฐ์์ ์ญํ ๊ณผ ๋ถ๋ณํ์ null๋ฆฌํด
โถ์ฐธ์กฐ, ๋ฐ์ฑ, ์ธ๋ฐ์ฑ, nullํ์ ์ฌ์ฉ
โถํ์
- ๊ฒฐ๊ณผํ = ์ฐธ์กฐํ, ์ธ๋ฐฉ์, ๋ฐฉ์ as ๋ณํํ
namespace ConsoleApp4
{
class A
{
}
class B
{
}
class Program
{
static void Main(string[] args)
{
string str1 = "123";
object obj = str1;
string str2 = obj as string;
Console.WriteLine(obj);
Console.WriteLine(str1);
Console.WriteLine(str2);
A test1 = new A();
object obj1 = test1;
B test2 = obj1 as B;
if(test2 == null)
{
Console.WriteLine("ํ๋ณํ ์คํจ");
}
else
{
Console.WriteLine("ํ๋ณํ ์ฑ๊ณต");
}
}
}
}
๐ง null ๋ณํฉ ์ฐ์ฐ์
โถ ? ? (null ์กฐ์ฌ)
โถC = A ? ? B
- A๊ฐ null์ด ์๋๋ฉด A๋ฅผ C์ ๋์
- A๊ฐ null์ด๋ฉด B๋ฅผ C์ ๋์
์๋ฐ์ ์ผํญ์ฐ์ฐ์๋ ๋น์ทํ๊ตฌ๋ง!
namespace ConsoleApp4
{
class Myclass
{
static void Main(string[] args)
{
int? x = null; // nullableํ์, null ์ ์ฅ ๊ฐ๋ฅ
int y = x ?? -1; // x๊ฐ null์ด๋ฏ๋ก y = -1
Console.WriteLine(y); // -1
x = 10;
y = x ?? -1; //x๊ฐ 10์ด๋ฏ๋ก y = 10
Console.WriteLine(y); // 10
}
}
}
'C#' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[C# ๊ธฐ์ด๊ณต๋ถ] ์ ํ๋ฌธ(goto, continue, return, break)/ ์์ธ ์ฒ๋ฆฌ๋ฌธ(if~else)(try~catch)(try~finally)(throw) (0) | 2023.01.06 |
---|---|
[C# ๊ธฐ์ด๊ณต๋ถ] ์ ํ๋ฌธ (if~else)(switch, case) (0) | 2023.01.04 |
[C# ๊ธฐ์ด๊ณต๋ถ] ๊ฐ ํ์,์ฐธ์กฐํ์ (0) | 2023.01.04 |
[C# ๊ธฐ์ด๊ณต๋ถ] ๊ตฌ์กฐ์ฒด (0) | 2023.01.04 |
[C# ๊ธฐ์ด๊ณต๋ถ] ํ์ค ์ ๋ ฅ (0) | 2023.01.04 |