목록전체 글 (240)
S_pot
static void Main1(string[] args) { char[] byteArray = new char[] { '가', '나', '다' }; string aString1 = "테스트"; string aString2 = new string(byteArray); Console.WriteLine(aString1); Console.WriteLine(aString2); int iNum = "테스트".IndexOf('테'); // "테스트"를 앞서 String으로 선언했기 때문에 "테스트"를 String과 같게 인식한다. Console.WriteLine(iNum); // '테' = 0, '스' = 1, '트' = 2, 없는 문자는 -1로 출력된다. iNum = "지옥으로 지 키티".IndexOf('지');..
static void Main(string[] args) { int? a; // Nullable int b; // NonNullable Console.WriteLine("1---------------------"); a = null; //b = null; // null값은 nullable 변수만 대입가능 b = 0; Console.WriteLine("[" + a + "]"); Console.WriteLine("[" + b + "]"); Console.WriteLine("2---------------------"); Console.WriteLine(a.HasValue); // HasValue는 값이 null이면 False 그렇지 않으면 True //Console.WriteLine(b.HasValue); /..
static void Main(string[] args) { int iNum1 = 100; iNum1 = 200; Console.WriteLine("변수 iNum1 = " + iNum1); const int iNum2 = 100; // const 상수선언, 나중에 값 변경이 불가능하다. //const int iNum3; // 상수이기 때문에 생성할 때 //iNum3 = 100; // 값을 바로 초기화해야 한다. // iNum2 = 200; // 상수로 만들면 변경이 불가능하다. Console.WriteLine("상수 iNum2 = " + iNum2); }
using static System.Console; namespace Second { class Smart { } } namespace First { class Smart { static void Main(string[] args) { First.Smart aSmart1 = new First.Smart(); First.Smart aSmart2 = new First.Smart(); Second.Smart aSmart3 = new Second.Smart(); aSmart1 = aSmart2; //aSmart1 = aSmart3; // namespace가 같지않아 적용할 수 없다.(다른클래스이므로 대입불가) // namespace를 분리함으로써 이름이 충돌하는 것을 사전에 방지할 수 있다. WriteLine(..
13이 소수인지 검색하는 코드 static void Main(string[] args) { // 13이 소수인지 검색하는 코드 int Num; for (Num = 2; Num < 13; ++Num) { //Console.WriteLine(Num); // 잿수 //Console.WriteLine(13%Num); // 나머지 출력 if (13 % Num == 0) // 13이 나누어지는 경우, 소수가 아닌 경우 { break; } } if (Num == 13) { Console.WriteLine("13은 소수입니다."); } } 임의의 숫자가 소수인지 판별하는 코드 static void Main(string[] args) { // 소수인지 검색하는 소스 int PrimeNumber = 97; // 변수를 지..

using System; namespace _210517_007 { class Human { public double tall; // 변수생성 public void eat() // 메서드생성 { Console.WriteLine("냠냠냠..."); } } class Program { static void Main(string[] args) { int iNum; // 기본형: int Human HumanObject; // 기본형: 객체참조변수, 이것은 객체가 아니라 객체를 참조하는 변수, 위치만 가지고 있기 때문에 크기는 고정 iNum = 100; HumanObject = new Human(); // HumaObject는 객체의 위치이고 new Human()은 객체를 생성한 것이다.(인스턴스 생성) Huma..
static void Main(string[] args) { int iNum = 100; // 본명 ref int riNum = ref iNum; // 예명, 앞에 ref를 붙여주어야 한다. riNum에 200을 넣으면 iNum도 200이 된다. riNum = 200; Console.WriteLine("iNum = " + iNum); } static void Main2(string[] args) { uint iNum = 64; // 0x는 뒤에 숫자가 16진수를 의미 Console.WriteLine(iNum); } using System; namespace _210517_006 { class Program { static void Smart(ref int Number) // ref:래퍼런스(참조), 호출..