C#/C#
[C#]๋ฌธ์์ด ์ถ๋ ฅ ์ฌ๋ฌ๊ฐ์ง ๋ฐฉ๋ฒ
Rainbow๐Coder
2022. 2. 4. 18:44
728x90
[C#] string format, ๋ฌธ์์ด ๋ณด๊ฐ($)์ ์ด์ฉํ ๋ฌธ์์ด ์ถ๋ ฅ๋ฐฉ๋ฒ (tistory.com)
[C#] string format, ๋ฌธ์์ด ๋ณด๊ฐ($)์ ์ด์ฉํ ๋ฌธ์์ด ์ถ๋ ฅ๋ฐฉ๋ฒ
์๋ ํ์ธ์. BlockDMask ์ ๋๋ค. ์ค๋ ๊ณต๋ถํ ๋ด์ฉ์ C#์ string ์ถ๋ ฅ ๋ฐฉ๋ฒ์ ๋๋ค. C#์์๋ string์ ์ถ๋ ฅํ๋ ์ฌ๋ฌ๊ฐ์ง ๋ฐฉ๋ฒ์ด ์กด์ฌํ๋๋ฐ์, ๊ทธ๋ฅ ์ถ๋ ฅํ๋ ๋ฐฉ๋ฒ, format์ ์ด์ฉํ ๋ฐฉ๋ฒ ๊ทธ๋ฆฌ๊ณ ๋ฌธ์์ด
blockdmask.tistory.com
1.
using System;
using System.Collections.Generic;
using System.Text;
using static System.Console;
namespace Hello
{
class MainApp
{
static void Main(string[] args)
{
byte a = 240;
int aa = 2424;
string aaa = "you";
int num = 999;
string str1 = string.Format("Example2 : {0}, {1}, {2}", "BlockDMask", 3434, num);
string str2 = $"a={a} {aa} {aaa}";
WriteLine(str1);
WriteLine(str2);
}
}
}
์ถ๋ ฅ
Example2 : BlockDMask, 3434, 999
a=240 2424 you
2.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
namespace Hello
{
class MainApp
{
static void Main(string[] args)
{
byte a = 240;
int aa = 2424;
string aaa = "you";
WriteLine($"a={a} {aa} {aaa}");
WriteLine("a={0} {1} {2}", a,aa,aaa);
WriteLine("a={0} {1} {2}", 240, 2424, "you");
}
}
}
์ถ๋ ฅ
a=240 2424 you
a=240 2424 you
a=240 2424 you
๋๋ ์ :
C#์์๋ $ ๊ธฐํธ๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ๊ต์ฅํ ํธ๋ฆฌํ ๊ฒ ๊ฐ๋ค.
$ํ์ํ ๋ค์ {} ๊ดํธ ์์ ๋ณ์๋ฅผ ๋ฃ์ด๋ ๋๊ณ ์ง์ ์ ์ธ ๊ฐ์ ๋ฃ์ด๋ ์ถ๋ ฅ์ด ๋๊ณ
WriteLine๊ณผ์ ํธ์๋ ์ข๊ณ ,
๊ทธ ์์ฒด๋ก string ๋ณ์์ ๋ด์ ์๋ ์๋ค.
728x90