Blog Content

  • 83.C# - 표준쿼리문 ( 무명메서드, 람다식 )

    Category C# on 2009. 8. 19. 21:15

    표준쿼리문으로 무명메서드, 람다식으로 호출하는 예제입니다. Program.cs using System; using System.Collections.Generic; using System.Linq; public class 표준쿼리연산자 { public static bool EvenNum(int x) { return (x % 2 == 0); } public static void Main() { //Input int[] data = { 3, 5, 4, 2, 1 }; //Process var q = //from d in data select d; //전체 출력 //from d in data where d % 2 == 0 orderby d select d;[1]쿼리식 //from d in data where d..

    Read more
  • 82.C# - IEnumerabel Interface (C# LINQ)

    Category C# on 2009. 8. 19. 20:45

    IEnumerabel은 한정된 형식의 컬렉션을 단순하게 반복할 수 있도록 지원하는 열거자를 노출자로 여기서 처음 사용되는 LINQ는 C#언어에서 사용되는 독립적인 쿼리문으로 데이터베이스에서는 SQL문으로 쉽게 저장된 정보를 원하는 값만을 쉽게 뽑아 쓰는 것입니다. Program.cs using System; using System.Collections.Generic; using System.Linq; public class IEnumerable인터페이스 { public static void Main() { //LINQ int[] data = { 3, 5, 4, 2, 1 }; //IEnumerable 인터페이스 변수 선언/초기화 : LINQ(언어 통합 쿼리) IEnumerable query = from d..

    Read more
  • 81.C# - 람다식

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

    람다 식은 식과 문을 포함하고 대리자나 식 트리 형식을 만드는 데 사용할 수 있는 익명 함수입니다. [MSDN] Program.cs //정수 하나를 입력받아서, 그 수를 2배하는 예제입니다. using System; public class 람다식 { public static void Main() { Console.WriteLine(Plus(2)); //[1] 메서드 plusHandler ph = delegate(int a) { return (a + a); //[2]무명메서드 }; Console.WriteLine(ph(2)); //[3]람다식 : 간결, 빨리, 같은 타입이면 짧게 = 람다식 plusHandler labda = a => a + a; //(매개변수) => 실행문; Console.WriteLin..

    Read more
  • 80.C# - 확장메서드

    Category C# on 2009. 8. 19. 19:51

    확장 메서드 : 기존 클래스의 외부에서 메서드 추가 static 메서드로 새 파생형식을 만들거나 다시 컴파일 또는, 원래 형식을 수정안해도 기존 형식의 메서드를 "추가" 할 수 있습니다. 덧셈하기 위한 클래스에 뺄셈기능을 추가하고자 할때 확장 메서드 사용하는 예제 Program.cs using System; public class Calc { public int plus(int a, int b) { return (a + b); } } public static class CalcExtension //확장메서드 사용한 클래스 선언 { public static int Minus(this Calc c, int a, int b) { return (a - b); } } public class 확장메서드 { publ..

    Read more
  • 01.C#-Console 성적입력 출력

    Category C# on 2009. 8. 19. 19:40

    Visual Studio 2008 C# Console에서 작성된 성적입력 예제입니다. [출처 - 멍멍] Program.cs using System; using System.Collections.Generic; public class MyClass { public static void Main(string[] args) { List lst = new List(); Cals p1; string tempNum; string tempEnglish; string tempJapan; string btn = "n"; bool flag = false; do { p1 = new Cals(); Console.WriteLine("자료를 입력하세요."); Console.Write("학생번호 : _\b"); tempNum = ..

    Read more
  • 13.C# - 알고리즘 : 그룹

    Category C# on 2009. 8. 18. 21:22

    group 절은 그룹의 키 값과 일치하는 하나 이상의 항목을 포함하는 IGrouping (TKey, TElement)개체 시퀀스를 반환합니다. 예를 들어 각 문자열의 첫 글자에 따라 문자열 시퀀스를 그룹화할 수 있습니다. 이 경우 첫 글자가 키가 되고 키의 형식은 char이며 각 IGrouping)개체의 Key 속성에 저장됩니다. 컴파일러가 키의 형식을 유추합니다. [출처-멍멍,MSDN] Program.cs using System; using System.Collections.Generic; public class ProductInfo { public string Name { get; set; } // 상품명 public int Quantity { get; set; } // 판매량 public Produ..

    Read more
  • 78.C# - 초기화자

    Category C# on 2009. 8. 18. 20:47

    Program.cs using System; using System.Collections.Generic; public class ProductInfo { //Name 속성 private string _Name; public string Name { get { return _Name; } set { _Name = value; } } //Quantity 자동 속성 : 3.0의 특징 public int Quantitiy { get; set; } //Method public void Print() { Console.WriteLine("{0} {1}", Name, Quantitiy); } //Constructor public ProductInfo(string name, int quantity) { this.Nam..

    Read more
  • 77.C# - Attribute 사용자 정의 특성

    Category C# on 2009. 8. 18. 20:39

    사용자 지정 특성에 대한 기본 클래스를 나타냅니다.msdn에 있는 예제입니다. Program.cs 01 using System; 02 namespace 사용자정의특성 03 { 04 [AttributeUsage( AttributeTargets.Method | 05 AttributeTargets.Property |AttributeTargets.Class,AllowMultiple=true)] 06 07 public class AuthorAttrubite : Attribute //작성자 정보를 저장 하는 특성 08 { 09 //private string name; //필드 10 public string name; //사용자정의 특성을 불러오기 위해 name을 11 private에서 public로 변경 12 13..

    Read more
  • 76.C# - Attribute 특성 (에트리뷰트)

    Category C# on 2009. 8. 18. 20:19

    에트리뷰트 코드에 대한 설명문 (매타데이타)1. 멤버 앞에 [특성(특성값)] 식으로 붙여서 사용 (예:Obsolete)2. 분야 (Web,XML..) 에 따라서 많은 내장 특성3. 사용자 정의 특서을 만들고자 할 대에는 System.Attribute를 상속 받아 설계4. 특성을 통해서 런타임 시에 추가적인 기능을 부여 가능 5. 자동차로 따지자면, 자동차 엑세서리 [출처|작성자 멍멍] Program.cs using System; public class 특성 { public static void Main() { Say1(); Say2(); } /// /// 닷넷 1.0버전 /// [Obsolete ("현재 메서드는 오래된 버전이므로, Say2()를 사용하세요",true) ] //런타임시 경고문. 기본 fa..

    Read more
  • 75.C# - 형식 매개변수에 대한 제약조건

    Category C# on 2009. 8. 18. 19:47

    제네릭 클래스를 정의하는 경우 클래스를 인스턴스화할 때 클라이언트 코드에서 형식 인수에 사용할 수 있는 형식의 종류에 제약 조건을 적용할 수 있습니다. 클라이언트 코드가 제약 조건에서 허용하지 않는 형식을 사용하여 클래스를 인스턴스화하려고 하면 컴파일 타임 오류가 발생합니다. 이러한 제한을 제약 조건이라고 합니다. 제약 조건은 컨텍스트 키워드 where를 사용하여 지정합니다. where T: struct -> 형식 인수는 값 형식. Nullable를 제외한 임의의 값 형식 지정가능 where T : class -> 형식 인수는 참조 형식 (모든 클래스, 인터페이스, 대리자 또는 배열 형식에도 적용) where T : new() -> 형식 인수가 매개 변수 없는 공용 생성자여야 함. 다른 제약 조건과 함께..

    Read more
  • 74.C# - 제네릭 클래스 (Generic Class)

    Category C# on 2009. 8. 18. 19:35

    Program.cs using System; public class 제네릭클래스 { public static void Main() { //기본클래스 메서드 호출 //Hello h = new Hello(); h.SayInt(1234); h.SayStr("안녕"); //제네릭 클래스 호출 Hello hi = new Hello(); hi.Say(1234); Hello hs = new Hello(); hs.Say("안녕"); //생성자 호출 Hello say = new Hello("반갑습니다."); say.Say(); say.SayType(); } } //제내릭 클래스 설계 public class Hello //제내릭 메서드로 설정 { //public void SayInt(int msg) { Console.Wr..

    Read more
  • 73.C# - 연산자 오버로드

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

    Program.cs using System; public class 연산자오버로드 { public static void Main() { //선언과 동시에 초기화 변환연산자 사용 (int 키워드를 Integer로 모방) //Integer i = new Integer(10); Integer i = 10; //위 라인 대체 Integer j = 20; //Integer j = new Integer(20); Integer k = 0; //Integer k = new Integer(0); //i.Value++; i++; //단항 연산자 오버로드 --j; //Integer k = i + j; //k.Value = i.Value + j.Value; k = i + j; //이항 연산자 오버로드 k = k - i; Co..

    Read more
  • 72.C# - 리스트 제네릭 클래스 ( List Generic Class)

    Category C# on 2009. 8. 18. 00:29

    네임스페이스인 System.Collections.Generic; 를 선언하게 되면 리스트 제네릭 을 사용할 수 있습니다. 리스트 제네릭 클래스는 어떠한 자료 형태도 다 받아 드릴 수 있어 코드의 간결화로 개발자 입장에서는 유용한 클래스 입니다.사용-예)ArrayList를 대신해서 사용 Program.cs using System; using System.Collections.Generic; public class 리스트제네릭클래스 { static void Main() { //정수형 List su = new List(); su.Add(10); su.Add(20); su.Add(30); for (int i = 0; i < su.Count; i++) { Console.WriteLine("{0}",su[i]); ..

    Read more
  • 71.C# - 예외처리

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

    예외처리 Exception : 오류(Error)컴파일(문법) 오류 : 잘못된 타이핑, 잘못된 문법이면 visual stdio가 바로 잡아줌 - 오류 줄일려면 많은 타이핑, 많은 학습런다임(실행) 오류 : 실행시 발생 -많은 테스트논리(잘못된분석) 오류(예외처리) : 잘못된 분석/설계/구현(오탈자) -많은 프로그램 작성 경험 Program.cs using System; public class 예외처리 { static void Main(string[] args) { //int c = 5 / 0; //1. 문법 오류 //int a = 5; int b = 0; int c = a / b; //빌드하면 문법 오류없음 2. 실행시 애러(런타임 오류) //int c = args+bool; //논리상 나누기가 필요한데 ..

    Read more
  • 70.C# - 변환연산자

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

    선언과 동시에 초기화 하는 예제입니다. Program.cs 01 using System; 02 public class 변환연산자 03 { 04 public static void Main() 05 { 06 //Car car; 07 //car = new Car("에쿠스"); 08 09 //Car car = new Car("에쿠스"); 10 11 Car car = "에쿠스"; 12 13 Console.WriteLine("{0}",car.Name); 14 } 15 } 7+8 =11번줄이 되고 11번줄을 좀더 줄여서 12번 라인으로표시하기 원칙적 선언과 동시에 초기화 위해 변환연산자 구현한다. //11번 라인 Car car = new Car("에쿠스"); 을 변환연산자라 한다. Car.cs using System..

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