728x90
반응형

표준 출력 함수


  • Console.Write(), Console.WriteLine() 차이점

      Console.WriteLine() : 한줄 띄어서 출력

 

  • 메서드 원형

      public static void Write(bool value);

      public static void Write(string format, Object arg0);

      public static void WriteLine(bool value);

      public static void WriteLine(string format, Object arg0);

 

출력 형식


  • Console.Write(변수 또는 데이터);

  • Console.Write("{0} {1}", 변수1, 변수2);  // "{0} {1}" 출력 형식 문자열

  • Console.Write()를 사용하여 Hello World 출력

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}
  • 3.14f와 12출력

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("{0} {1}", 3.14f, 12);
        }
    }
}
  • 입력값 1, 2를 더한 1 + 2 = 3과 같이 출력

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("{0} + {1} = {2}", 1, 2, 1+2);
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("{0:C} {1:P} {0:X}", 123, 123.45);
        }
    }
}

출력 형식 문자를 사용한 출력


  • 출력 형식 문자 -> MSDN 참고

형식 문자 내용
C 통화($, \ 등) 표시
D 10진수 정수
E 지수형태 출력 
F 부동소수점 출력
G 기본 출력

 

형식 문자 내용
N 콤마 출력
P % 단위로 출력
X 16진수 출력

C# 키워드

 

총 77개

C 키워드 (26개)

break, case, char, const, continuew,

delfault, do, double, else, enum, extern, float, for, goto, if, int, lomg, return, short, sizeof, static,

struct, switch, typeo, fvoid, while

 

c++ 키워드 (19개)

bool, catch, calss, false, finally, namspace, new, private, protected,

explicit, operator, publuic, this, throuh, true, try, using, virtual, volatille

 

C# 키워드 (32개)

abstract, as , base, byte, checked, decimal, delegate, event, fixed, foreach in, in terface,

internal, implicit, is, look, null, object, out, override, params, readonly, ref, sbyte, sealed,

string, uint,, unlong, .unchecked, nusafe, unshort, volatile


본 글은 C#으로 살아남기 _나우캠퍼스를 보고 정리하였습니다.
728x90
반응형

+ Recent posts