namespace StringManipulation;
class Program
{
static void Main(string[] args)
{
//define few variables
int age = 7;
string name = "fred";
string job = "student";
// 1. string concatenation
Console.WriteLine("String Concaenation");
Console.WriteLine("Hi i'm " + name + " ,i'm " + age+"years old");
// 2. String formatting
// string formatting uses index
Console.WriteLine("String Formattion");
Console.WriteLine("Hi i'm {0}, i'm {1} years old", name, age);
// 3. String interpolation
// variables like this {var}
Console.WriteLine("String Interpolation");
Console.WriteLine($"Hi i'm {name}, i'm {age} years old. i'm a {job}");
// 4. Verbatim strings.
// literally and ignore any spaces and escape characters like \n
Console.WriteLine("Verbatim strings");
Console.WriteLine(@"hi
i'm who");
//instead of using \\ to write file paths we can use verbatim string to make it easier
Console.WriteLine(@"/Users/bdins/ChatGPT_logo.svg.png");
//with verbatim strings even vaild escape characters won't work
Console.WriteLine(@"huk! \n u have no powers here");
Console.WriteLine("huk! \n u have powers here");
}
}
1. string concatenation 결과

2. string formatting 결과

3.string interpolation 결과

4.verbatim strings 결과

'c# ☃️' 카테고리의 다른 글
[c#] string 안에 따음표 ” 슬래쉬 / 사용 (1) | 2024.03.04 |
---|---|
[c#] variable string method - 특정시작/대문자/소문자/공백제거/인덱스/포맷 (0) | 2024.02.21 |
[c#] string -> int 파싱 (0) | 2024.02.19 |
[c#] double->int / float->string / double->string / bool->string (0) | 2024.02.19 |
[c#] c# 프로젝트 구조 (1) | 2023.12.18 |