Blog Content

  • 69.C# - 반복기

    Category C# on 2009. 8. 17. 23:38

    반복기는 for문/foreach문이 필요할때 호출해서 사용하는 방법입니다. Program.cs //Iterator : 내가 만든 객체를 foreach문으로 //돌리고자할 때 반복기가 구현되어있어야 함... using System; class 반복기 { static void Main(string[] args) { int[] data = { 1, 2, 3 }; foreach (var item in data) //var 대신 int로 써도 됨 { Console.WriteLine(item); } Car hyundai;//Class hyundai= new Car(3); //Constructor hyundai[0] = "에쿠스"; //Indexer hyundai[1] = "제네시스"; hyundai[2] = "그랜..

    Read more
  • 68.C# - 암시적으로 형식화된 로컬변수 (var)

    Category C# on 2009. 8. 17. 23:24

    Program.cs using System; namespace 암시적으로형식화된로컬변수 { class Program { static void Main(string[] args) { int a = 10; //변수 선언 int? b = null; //Nullable 형식 //암시적으로 형식화된 로컬 변수 var i = 1234; //알아서 초기화되는 값으로 선언 var s = "1234"; //타입 출력 Console.WriteLine("{0}", i.GetType()); //Int32 Console.WriteLine("{0}", s.GetType()); //String } } } 결과화면

    Read more
  • 67.C# - 분할클래스

    Category C# on 2009. 8. 17. 23:17

    불할클래스는 동일한 클래스를 여러개 파일에 걸쳐 나눠서 설계를 하지만 실제 빌드(컴파일)했을 때에는 단일 클래스로 합쳐집니다. Program.cs using System; public partial class Car { private string name; //Field } public partial class Car { public void Run() //Method { Console.WriteLine("{0}가 달리다", this.name); } } Car.cs using System; class 분할클래스 { static void Main(string[] args) { Car s = new Car("소"); s.Run(); } } public partial class Car { public Car(..

    Read more
  • 66.C# - 추가연산자

    Category C# on 2009. 8. 17. 21:28

    참조타입 관련 연산 예제 입니다. Program.cs using System; class 추가연산자 { static void Main(string[] args) { int i = 10; //값 형식은 사용불가 (기본) string s = "안녕"; object o = "Hi"; int? num = null; // ??연산자는 Nullalbe 가능 Console.WriteLine("{0}", o is string); //True Console.WriteLine("{0}", o as string); //(o is string) ? o :null //변환 그렇지 않으면 null Console.WriteLine("{0}", (num ?? 1234) ); //(num is null)?1234 : num; } //..

    Read more
  • 65.C# - 값형식과 참조형식 ( Boxing 과 UnBoxing )

    Category C# on 2009. 8. 17. 20:42

    .Net FrameWork영역 운영체제와는 별계로 값이 스택에 붙으면 value이고 힙에 붙으면참조형 언박싱 -> 스택 (힙영역의 값을 푸는것) / 박싱 -> 힙 (형 변환) Program.cs using System; class 값형식과참조형식 { static void Main(string[] args) { //값 형식 : Value Type : 닷넷이 관리하는 메모리의 스택에 보관 int i = 1234; //참조 형식 : Reference Type : 닷넷의 힙 메모리에 보관 string s = "안녕\0하세요"; //리터널(Literal) Console.WriteLine(s); //박싱(Boxing)과 언박싱(UnBoxing) string su = "1234"; int num = Convert.T..

    Read more
  • 65.C# - Nullable (널 기능 형식)

    Category C# on 2009. 8. 17. 19:57

    정수형 등의 변수는 반드시 초기화해서 사용해야 한다.변수 선언시 ?를 붙이면 null 값으로 초기화할 수 있다. Program.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Nulilable { class Program { static void Main(string[] args) { int i = 100; //double nd = null; // ? 붙이지 않으면 null값으로 처리안됨 int? ni = null; double? nd = 12.34; if (ni.HasValue) { //널값이면 false, 값이 있으면 참 Console.WriteLine("{0}", ni.V..

    Read more
  • 64.C# - 명령줄인수 - 2 - ( command Line Prompt )

    Category C# on 2009. 8. 17. 18:31

    Program.cs using System; namespace MyCalc { class Program { static void Main(string[] args) { if (args.Length < 3) { Console.WriteLine("명령줄인수는 3개 이상 필요합니다."); return; } int first = Convert.ToInt32(args[0]); int second = Convert.ToInt32(args[2]); string calc = Convert.ToString(args[1]); int r = 0; if (args[1] == "+") { r = first + second; } else if (args[1] == "-") { r = first - second; } else if..

    Read more
  • 63.C# - 명령줄인수 ( Commands Line Prompt )

    Category C# on 2009. 8. 17. 18:26

    예제입니다.dir c"\ 식으로 명령어(exe) 뒤에 따라오는 문자열예) 명령줄인수.exe 1 100 3 =>1 부터 100까지 3의 배수 합을 구하는 프로그램예)명령줄인수.exe 1 50 2 =>1부터 50까지 2의 배수의 합을 구하는 프로그램 Program.cs using System; using System.Collections.Generic; using System.Text; namespace 명령줄인수 { class Program { static void Main(string[] args) { if (args.Length < 3) { Console.WriteLine("명령줄인수는 3개 이상 필요합니다."); return; } int first = Convert.ToInt32(args[0]); i..

    Read more
  • 62.C# - 봉인클래스 (sealed Class)

    Category C# on 2009. 8. 15. 00:20

    봉인클래스(Sealed) : 최종 클래스, 마지막 클래스 - 더 이상 상속되지 않는 클래스 - Sealed 키워드를 붙여서 상속금지 sealed를 메서드 앞에 붙이게 되면 해당 메서드는 봉인되어 재정의 되는것을 막을 수 있어 클래스에 적용할 경우 상속된 메서드를 재정의 할 수 없으며 호출만 가능합니다. Program.cs using System; public class 봉인클래스 { public static void Main() { Sonata s = new Sonata(); } } Car.cs using System; public interface IIso { } public interface IKs { } public abstract class Car { } public class Hyundai : ..

    Read more
  • 61.C# - 인터페이스 (Interface)

    Category C# on 2009. 8. 14. 23:40

    추상클래스와 같이 다른 클래스에게 멤버명을 미리 강제로 사용토록 할 때 사용 - 인터페이스는 멤버명만 갖는 반면, 추상클래스는 다른 멤버도 가질 수 있다. - 인터페이스는 자동차로 따지면, 전세계표준(ISO), 국내표준㉿ 등의 의미 가짐. - C#은 다중상속이 불가능하지만(C++가능), 인터페이스 다중 상속은 가능하다. - 자동차 규격, 예를 들어 배터리 충전(점프선) 인터페이스란 클래스의 한 종류로 인터페이스로 부터 상속 받은 클래스는 인터페이스에서 정의한 메서드를 사용해야 합니다.인터페이스에는 필드가 포함되지 않습니다. Program.cs using System; public class 인터페이스 { public static void Main() { Sonata sonata = new Sonata()..

    Read more
  • 60.C# - 추상클래스 (Abstract Class)

    Category C# on 2009. 8. 14. 23:19

    -클래스 설계 시 부모 클래스 역할을 하면서 강제로 자식 클래스에게 특정 멤버명을 물려주고자 할 때 정의 -추상클래스는 멤버의 실제 내용을 구현하지 않고, 자식 클래스에서 멤버를 구현 -주로 선임이 추상클래스, 후임이 추상클래스를 상속받은 클래스 구현 추상클래스는 다른 클래스의 기본클래스만 사용되는 것을 나타냅니다.Abstract로 표시된 클래스에 포함된 맴버는 Abstract에서 파생되는 클래스에 구현되어야 합니다.추상클래스는 트리구조를 사용하는데 유용하며 추상클래스로 파생된 클래스는 overide를 이용하며 파생되는 클래스에 의해 구현되어야 합니다. Program.cs using System; public class 추상크래스 { public static void Main() { Sonata son ..

    Read more
  • 59.C# - ToString메서드오버라이드 ( ToString Method Override )

    Category C# on 2009. 8. 14. 21:07

    - Object클래스에 정의되어 있는 ToString()메서드는 기본적으로 클래스의 이름값을 반환시켜준다. - 또는 정수형과 같이 대표가 되는 값이 들어있는 경우는 그 값을 문자열로 변환해서 출력해준다. - 내가 만든 클래스의 대표가 되는 속성 또는 값을 외부에 인스턴스명으로 사용해서 출력 할 때는 ToString()메서드를 재정의(오버라이드) 후 사용한다. ToString Method Override 관련 예제입니다. Program.cs using System; public class ToString메서드오버라이드 { public static void Main() { //문자열 변수 : 클래스명 System.Collections.Stack s = new System.Collections.Stack();..

    Read more
  • 58.C# - 부모의멤버접근

    Category C# on 2009. 8. 14. 20:31

    Program.cs using System; public class 부모의멤버접근 { public static void Main() { Hyundai sonata = new Hyundai("소나타"); sonata.Run(); //소타나가 달린다. Hyundai santafe = new Hyundai(); santafe.Run(); //자동차가 달린다. Samsung sm = new Samsung(); sm.Run(); } } Car.cs using System; public class Car { private string name; //이름 저장 public Car(){} public Car(string name) //생성자 지정 this.name = name; } public void Run() { ..

    Read more
  • 57.C# - 클래스상속 -2- ( ClassInheritance )

    Category C# on 2009. 8. 14. 20:17

    메서드 재정의 입니다. 자식클래스가 부모클래스로 부터 상속받은 함수를 재정의 해서 사용하는 방법입니다.부모클래스의 함수 앞에 virtual 을 붙여주고 자식클래스는 함수 앞에 override를 붙여줍니다. Program.cs using System; public class 상속 { public static void Main() { Hyundai sonata = new Hyundai(); sonata.Run(); //공통 sonata.Left(); //전용 GM matiz = new GM(); matiz.Back(); matiz.Right(); } } Car.cs using System; //공통 public class Car : Object { //자식에게만 보여주고 싶을때 사용 protected voi..

    Read more
  • 56.C# - 클래스상속 ( ClassInheritance )

    Category C# on 2009. 8. 14. 19:46

    - 개체 지향 프로그래밍의 장점 중의 하나는 이미 만들어져 있는 클래스를 재사용 하는 것이다. 이 때 재사용의 대한 핵심 개념이 바로 상속이다. - 부모의 재산을 자식에게 상속하듯이 부모클래스(기본클래스)의 모든 멤버를 자식클래스(파생클래스)에게 재사용토록 허가하는 기능을 의미한다. -여러 클래스들 간의 관계를 설정함에 있어서 수평관계가 아닌 부모와 자식간의 관계처럼 계층적인 관계를 표현하고자 할 때 사용하는 개념을 상속이라 한다. 부모와 자식관계를 가진 클래스 입니다.부모클래스 상속받아 자식클래스가 상속받은 속성을 사용하는 예제입니다. Program.cs using System; public class 클래스상속 { public static void Main(string[] args) { c.Hi2()..

    Read more
1 ··· 3 4 5 6 7 8 9 ··· 11