<문자열 표현식>(" "+" "+a+" ");, (" {0}",a);, ($"{a}");

C#/과제 2019. 3. 24. 01:19
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
29
30
31
32
33
34
35
36
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
 
namespace _20190322
{
    class Program
    {
        static void Main(string[] args)
        {
            string name = "Mark";//docs에서 긁어온 예문, 분석필요.
            var date = DateTime.Now;
            Console.WriteLine("Hello, {0}! Today is {1}, it's {2:HH:mm} now.", name, date.DayOfWeek, date);//예문1
            Console.WriteLine($"Hello, {name}! Today is {date.DayOfWeek}, it's {date:HH:mm} now.");//예문2
 
            Console.WriteLine("Hello, " + name + "! Today is " + date.DayOfWeek + ", it's " + date + " now");//직접 만든거..?
 
            //Console.WriteLine("%d %s와 같은 걸 여기선 그냥 {0}, {1}, {2}, {3}순서로 두고 ",name 같은 변수를 주나봄);
            int a = 1;
            float b = 1.1f;
            char ch = 'x';
            string str = "기모띠";
 
            Console.WriteLine("앙~{0}, {1}, {2}, {3}", a, b, ch, str);//직접 만들어본거1
            Console.WriteLine($"{str}");//($"")를 하면 {0}{1}같은거 없이 바로 안에 변수를 넣어서 변수'값'을 프린트 할 수 있습
            Console.WriteLine("{str}");//앞에 달러 표시 빼면 그대로 {str}을 출력해버림
            Console.WriteLine($"{{str}}");//그럼 {str}을 직접 프린트하고싶으면 어떡하나 싶어서 이것 저것 찍어본 결과 {{str}}하면 됨
            
            Console.ReadKey();
        }
    }
}
 
cs


: