반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Apache
- Redshift
- PostgreSQL
- c#
- matplotlib
- hive
- Google Excel
- django
- PANDAS
- string
- Tkinter
- PySpark
- array
- Excel
- Java
- math
- 파이썬
- Mac
- list
- SQL
- Python
- google apps script
- numpy
- Kotlin
- Github
- Google Spreadsheet
- gas
- dataframe
- GIT
Archives
- Today
- Total
달나라 노트
C# : if ~ else if ~ else (조건문), 한줄 if문 본문
728x90
반응형
C#에서 조건문은 다음과 같이 사용할 수 있습니다.
if (condition1)
{
condition1 = True일 경우 실행될 부분
}
else if (condition2)
{
condition2 = True일 경우 실행될 부분
}
else if (condition3)
{
condition3 = True일 경우 실행될 부분
}
else
{
모든 condition이 False일 경우 실행될 부분
}
else if 부분은 원하는 만큼 추가 가능합니다.
else if 부분은 아예 없어도 됩니다.
실제 예시를 봅시다.
using System;
class MyProgram
{
static void Main()
{
int test1 = 5;
if (test1 <= 3 )
{
Console.WriteLine("test1 <= 3");
}
else if (3 < test1 && test1 <= 6)
{
Console.WriteLine("3 < test1 <= 6");
}
else
{
Console.WriteLine("test1 > 6");
}
}
}
-- Result
3 < value <= 6
아래와 같은 구문을 이용하면 간단한 if문을 한줄에 적을 수 있습니다.
(condition) ? conditoin=true일 경우 return할 값 : condition=false일 경우 return할 값
아래 예시를 봅시다.
using System;
class MyProgram
{
static void Main()
{
int test1 = 3;
string result;
result = (test1 == 3) ? "test is 3" : "test is not 3";
Console.WriteLine(result);
}
}
-- Result
test is 3
728x90
반응형
'C# > C#' 카테고리의 다른 글
C# : for loop, foreach loop (반복문) (0) | 2022.03.23 |
---|---|
C# : switch ~ case (조건문) (0) | 2022.03.23 |
C# : substring (문자열 자르기) (0) | 2022.03.23 |
C# : 문자열 indexing (0) | 2022.03.23 |
C# : interpolation (문자열 format 기능 사용하기) (0) | 2022.03.23 |
Comments