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