class Parents { public Parents() { Console.WriteLine("부모"); } } class Child:Parents { public Child() { Console.WriteLine("자식"); } } class Program { static void Main(string[] args) { Child child = new Child(); } }// 결과 : 부모 \n 자식
string str = "안녕하세요 감쟈입니다 바보입니다"; Console.WriteLine(str.IndexOf("다")); //결과:10 Console.WriteLine(str.LastIndexOf("다"));//결과:16 IndexOf는 문장 안에 여러 단어가 있을 경우 가장 앞에 있는 문자열의 Index(감쟈입니다) LastIndexOf는 문장 안에 여러 단어가 있을 경우 가장 뒤에 있는 문자열의 Index(바보입니다)
string str = "안녕하세요"; char[] search_char_array = str.ToCharArray(); for (int i = 0; i < search_char_array.Length; i++) { Console.Write(search_char_array[i]); } Console.WriteLine(); //결과 : 안녕하세요 ToCharArray()는 string을 배열로 변환시키는 메서드이다
string str = "Hello My Name is Jia"; if (str.StartsWith("Hello")) { Console.WriteLine("내 블로그"); } if (str.StartsWith("Name")) { Console.WriteLine("제발"); } if (str.EndsWith("Jia")) { Console.WriteLine("구독해줘잉"); } // 결과 : 내 블로그 \n 구독해줘잉 문자열을 공백으로 구분하며 전위에 있는 문자열을 확인하는 메소드는 StartsWith() 후위에 있는 문자열을 확인하는 메소드는 EndsWith()
string str = "안녕하세요"; str = str.PadLeft(10, '뿡'); Console.WriteLine(str);//결과:"뿡뿡뿡뿡뿡안녕하세요" string str = "안녕하세요"; str = str.PadRight(10, '뿡'); Console.WriteLine(str);//결과:"안녕하세요뿡뿡뿡뿡뿡" PadLeft(), PadRight() 옆에 들어가는 숫자는 붙이고 싶은 문자(char)까지 합쳤을 때의 문자열의 총 길이를 말한다. 숫자가 str의 길이보다 작을 때는 원래 문자열만 출력한다.
int.Parse() 정의 : 숫자의 문자열 표현을 해당하는 32비트 부호 있는 정수로 변환. //Int.Parse 예제 string a="123"; int i=int.Parse(a); int.TryParse() 정의 : 숫자의 문자열 표현을 해당하는 32비트 부호 있는 정수로 변환. 반환 값은 작업의 성공 여부를 나타냄. //int.TryParse 예제 string a="123"; int i; int.TryParse(a, out i); int.Parse와 int.TryParse는 정수로 변환하려는 문자열을 정수로 변환할 수 없을 때 반응하는 방식에 있다. int.Parse()의 메서드는 int이며 반환할 수 없을 때, 예외를 발생시킨다. 반대로 int.TryParse()는 false의 bool 값을 반..