전체 글 (164) 썸네일형 리스트형 string using System; namespace myCSharp1 { class Program { static void Main(string[] args) { // string은 immutable 타입으로 string에 추가 문자열을 추가하면 배열을 재할당한다. string s2 = "Hello"; char c = s2[0]; Console.WriteLine(c); for (int i = 0; i < s2.Length; i++) { Console.WriteLine(s2[i]); } s2 += " World"; for(int i = 0; i < s2.Length; i++) { Console.WriteLine(s2[i]); } } } } 10진수, 2진수, 16진수로 변수에 값 할당하기 using System; namespace myCSharp1 { class Program { static void Main(string[] args) { byte a = 240; Console.WriteLine($"a={a}"); // 10 진수 byte b = 0b1111_0000; Console.WriteLine($"b={b}"); // 2 진수 byte c = 0xF0; Console.WriteLine($"c={c}"); // 16 진수 } } } Console 기능 using System; namespace myCSharp1 { class Program { static void Main(string[] args) { Console.SetWindowSize(80, 20); Console.SetCursorPosition(40,10); Console.WriteLine("Hello"); Console.ForegroundColor = ConsoleColor.Yellow; // ConsoleColor의 변수를 받아서 글자색을 변경 Console.BackgroundColor = ConsoleColor.Green; // 글자의 배경. Console.Clear(); // Clear()을 해주면, 전체 콘솔창의 내용 삭제 Console.Beep(); // 삑소리가 난다 } } } 헬로우 월드 using System; namespace myCSharp1 { class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); } } } C#의 요소들 클래스 단위로 존재한다. 화살표 입력값으로 글자 움직이기 #include #include #include using namespace std; int GetKey(void) { int ch = _getch(); if (ch == 0 || ch == 224) ch = _getch(); return ch; } // 커서 위치 이동 // 입력된 x,y 값으로 화면에 커서를 이동시켜주는 함수 void gotoxy(int x, int y) { COORD pos = { x,y }; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos); } void CursorView(bool show) { HANDLE hConsole; CONSOLE_CURSOR_INFO ConsoleCursor; hConsole = GetStd.. 출력할 때 글자색 바꾸기 #include #include using namespace std; void scolor(unsigned short text = 15, unsigned short back = 0) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), text | (back 화살표 입력값 받아서 출력하기 #include #include using namespace std; int GetKey(void) { int ch = _getch(); cout ctime #include #include using namespace std; int main() { //time_t time_t t = time(nullptr); cout 이전 1 ··· 4 5 6 7 8 9 10 ··· 21 다음