반응형
using System;
using System.Collections.Generic;
using System.Text;

namespace 필드멤버
{
    class Person
    {
        // const, readonly !! 
        // 공통점 ?? 선언과 동시에 초기화가 가능하다.. 
        // 값을 변경 할수 없다 !! 
        // 다른점??? 
        // const는 무조건 값을 변경할수 없고... 
        // readonly 생성자에서만 값을 변경할수 있다 !! 
        private static string nation;
        // static멤버는 static 프로퍼티로 .... 
        public static string Nation
        {
            get { return Person.nation; }
            set { Person.nation = value; }
        } 
        // 클래스의 멤버 변수를 선언과 통시에 초기화 !! 
         private const string jumin = "910101";
         private readonly bool sex = false;
         public bool Sex
         {
             get { return sex; }
         }
         private string name;
         public string Name
         {
             get { return name; }
             set { name = value; }
         }
         private int age;
         public int Age
         {
             get { return age; }
             set { age = value; }
         }
        //프로퍼티  !!
         public string Jumin
         {
             get 
             {
                 return jumin;
             }
         }
        // setter/getter 
         public string getJumin() { return Jumin; }
         public bool getSex() { return sex; }
         public string getName() { return Name; }
        public int getAge( ){ return Age;  }


         public Person() 
         {
       //      Jumin = "001111"; 
              sex = false; 

         }
       // public void SetSex( bool b) {  sex = b; }
       // 소멸자 !! 
          ~Person() // 오버로딩이 불가능 !! 
         { 
           
         }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Person p = new Person();
            Person.Nation = "xxx"; 

        }
    }
}

'C#' 카테고리의 다른 글

[C#] 추상클래스  (0) 2014.11.18
[C#] 인터페이스  (0) 2014.11.18
[C#] 인덱서  (0) 2014.11.18
[C#] 이벤트  (0) 2014.11.18
[C#] 예외처리  (0) 2014.11.18
반응형
using System;
using System.Collections.Generic;
using System.Text;

namespace 추상클래스
{
    // C#에서는 추상클래스에만  추상 메쏘드를  선언 가능 !! 
     abstract class Person
    {
         public int age; 
         // abstract  -->  virtual !!
        public abstract void Die();// 순수 가상함수 !! 
        public void Work() { } 

    }
    class buddist : Person
    {
        public override void Die()
        { 
 
        }
    }   
   
    class Program
    {
        static void Main(string[] args)
        {
           // Person p = new Person();
           // p.Die();
        }
    }
}
//  추상 클래스와 인터페이스 !! 
// 같은점 
//    - 객체를 직접 생성 불가능 !! 
//    - sealed 키워드??  사용불가 !! 
// 다른점 !! 
// 1)  추상 클래스에는 일반적인 함수의 구현과 추상 메소드 둘다 가능하다 !
//    -> 인터페이스에는 가상함수  가능하다 !!  
// 2) 인터페이스는 기본으로 public이다 !!  
// 3) 인터페이시는 인터페이스만 상속이 가능하다 !! 





abstract class  Person 
{
    private int age; 
    private string name; 
    
    public  abstract void work(); 
}

interface IStudy
{
    void Study(); 
}

interface IEmp
{
    void GetPay(); 
}


class Pro  : Person  ,IEmp
{


public void  GetPay()
{
 	throw new NotImplementedException();
}

public override void  work()
{
 	throw new NotImplementedException();
}
}



class Student : Person , IStudy 
{


public void  Study()
{
 	throw new NotImplementedException();
}

public override void  work()
{
 	throw new NotImplementedException();
}
}


'C#' 카테고리의 다른 글

[C#] 필드멤버  (0) 2014.11.18
[C#] 인터페이스  (0) 2014.11.18
[C#] 인덱서  (0) 2014.11.18
[C#] 이벤트  (0) 2014.11.18
[C#] 예외처리  (0) 2014.11.18
반응형
using System;
using System.Collections.Generic;
using System.Text;

namespace 인터페이스2
{

    class Car
    {
        private string CarNo;

  
        public void Power() 
        {
            Console.WriteLine("흡입 압축 폭발 배기 ");
        }
        public void ABS() 
        {
            Console.WriteLine(" anti lock break system"); 
        }
        public void Misson()
        {
            Console.WriteLine( " 1단 2단 3단 4단 5단 6단 후진 중립" ); 

        }
        public void Turbo() 
        {
            Console.WriteLine("과흡기  --> ");
        }
    }

    interface IDriver
    {
        void On();
        void Off();
        void Go();
        void Stop();          
    }
    class Explor : Car , IDriver
    {


        public void On()
        {
            throw new NotImplementedException();
        }

        public void Off()
        {
            throw new NotImplementedException();
        }

        public void Go()
        {
            throw new NotImplementedException();
        }

        public void Stop()
        {
            throw new NotImplementedException();
        }
    }


    class spark :  Car , IDriver
    {

        public void On()
        {
            throw new NotImplementedException();
        }

        public void Off()
        {
            throw new NotImplementedException();
        }

        public void Go()
        {
            throw new NotImplementedException();
        }

        public void Stop()
        {
            throw new NotImplementedException();
        }
    }
   


    class BestDriver
    {
        public void Drive( Explor explor )
        {
            explor.On(); 

        }
    }
    class Student : BestDriver 
    { 
    
    }
    class teacher : BestDriver
    { 
    
    }


    class Program
    {
        static void Main(string[] args)
        {
            Explor explor =  new Explor();
          //  K_madam k = new K_madam();
            


            BestDriver[] bd = new BestDriver[2];
            bd[0] = new Student();
            bd[1] = new teacher();
            bd[0].Drive(explor); 
            foreach (BestDriver  b in bd)
            {
                b.Drive(idriver); 
            }
            
            
            //   idriver.
            // 인터페이스의 구현 및 사용 !! 
            // 1) 다중상속처럼 사용할수 있다 !! 
            // 2) 프로그램의 결합도를  낮춘다 !! 

        


        }
    }
}

'C#' 카테고리의 다른 글

[C#] 필드멤버  (0) 2014.11.18
[C#] 추상클래스  (0) 2014.11.18
[C#] 인덱서  (0) 2014.11.18
[C#] 이벤트  (0) 2014.11.18
[C#] 예외처리  (0) 2014.11.18
반응형
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection; 

// 인터페이스 , 추상클래스 , 델리게이트,  이벤트, 어트리뷰 !! 

namespace 인덱서
{
    // 배열 !! 
    // --> 인덱스 --> []연산자를 이용해서 각각의 요소에 접근 !! 
    // 인덱스를 사용할수 있게 해주는것 !! 
    // []연산자를 오버로딩 !!    
    // C#에서는 [] 연산자를 통해 값에 접근 할수 있는 방법을 제공 !! 

    class MyArray
    {
        private int[] buf = new int[10];
        // 인덱서 !!
        public int this[int index]
        {
            get
            {
                return buf[index];
            }
            set
            {
                buf[index] = value;
            }
        }
        public int this[string str]
        {
            get { return this.buf[int.Parse(str)]; }
            set { this.buf[int.Parse(str)] = value; }
        }


    }

    class Program
    {
        static void Main(string[] args)
        {
            //1. 윈폼 트리 컨트롤로 구현하것 !
            //2. 똑같이 구현할것 !! 
            //3. C# 클래스 안에 들어갈수 있는 모든 것들에 대한 타입정보 !! 
            Assembly asm = Assembly.LoadFile(@"C:\Program Files\Microsoft ASP.NET\ASP.NET MVC 2\Assemblies\System.Web.Mvc.dll");
            Console.WriteLine(@"C:\Program Files\Microsoft ASP.NET\ASP.NET MVC 2\Assemblies\System.Web.Mvc.dll");
             Module [] modules =    asm.GetModules();
             foreach (Module module in modules)
             {
                   Console.WriteLine( "      "  + module.ToString());
                   Type[] type = module.GetTypes();
                   foreach (Type item in type)
                   {
                       Console.WriteLine( "            " + item.ToString());
                         MethodInfo [] mi =  item.GetMethods();
         
                         foreach (MethodInfo i in mi)
                         {
                             if( i.IsStatic ) 

                             Console.WriteLine("                 " + i.ToString());
                         }
                   }
             }
        }
    }
}

'C#' 카테고리의 다른 글

[C#] 추상클래스  (0) 2014.11.18
[C#] 인터페이스  (0) 2014.11.18
[C#] 이벤트  (0) 2014.11.18
[C#] 예외처리  (0) 2014.11.18
[C#] 생성자  (0) 2014.11.18
반응형
using System;
using System.Collections.Generic;
using System.Text;
//****************************************************************************
//  이벤트  
//****************************************************************************
// 특정 사건에 대한 알림 !! 
//  이벤트 처리기 ,  발생자 . 가입자  

namespace 이벤트
{
    class Button1
    {
        //  이벤트 발생하면 이벤트 처리함수를 저장하기 위한  대리자 !!  
        public delegate void MyDelegate(Object source, EventArgs e);
        // 이벤트 객체를 딜리게이트 객체와 함께 사용 !! 
        public static event MyDelegate myEvent;

        public static void CallEvent()
        {

            myEvent(  "ABC" , new EventArgs() ); 
        }

    }


    class Program
    {

        
        static void Main(string[] args)
        {

            Button1 btn1 = new Button1();
            Button1.myEvent += new Button1.MyDelegate(btn1_myEvent);
            Button1.CallEvent(); 

        }

        public static void btn1_myEvent(Object source, EventArgs e)
        {
            Console.WriteLine( source.ToString());
        }
    }
}

'C#' 카테고리의 다른 글

[C#] 인터페이스  (0) 2014.11.18
[C#] 인덱서  (0) 2014.11.18
[C#] 예외처리  (0) 2014.11.18
[C#] 생성자  (0) 2014.11.18
[C#] 상속  (0) 2014.11.18
반응형
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace 예외처리
{
// 예외  처리 !! 
// 예외 ??  에러?? 
//ex) 학년을 입력하세요??   :  5   
// 1,2,3,4
 //  예외 ?? 예상하는 결과에서 벗어난 결과 !! 
 // 1) 분기문을 이용한 예외처리 !! 
/*if( 1 || 2 || 3|| 4) 
{

}*/
 /*   switch (switch_on)
	{
		default: //  해당하는 케이스가 존재하지 않는 경우 !! 
	}
*/ 
    // try ~ catch ~ finaly  구조화된 예외처리 !! 

    // 예외는 실행시간에 발생하는 오류이다. 
    // try구문은 중첩이 가능하다 !!! 
    // 1) 가독성이 떨어진다 !! 
    // 2) 프로그램 코드와 예외처리 구문이 함께 공존한다 !! 
/*    int Result = 10; 
     if( Result == 1)  goto Failed; 
     f( Result == 2)  goto Failed; 
    if( Result == 3)  goto Failed; 
    if( Result == 4)  goto Failed; 

    Failed : 
    switch ()
	{
    //  예외처리구문 !! 
		default:
	}
    */





    class Program
    {
        static void Main(string[] args)
        {
            /*
            int no = 100;
            try
            { // 실제 우리가 구현하고자하는  로직 !!  
                int Result = no / 3;
            }
            catch { //예외 처리 코드 !! 
                Console.WriteLine("0으로 값을 나누는 것은 아무 의미가;;");
            }
            */

             FileInfo fi = new FileInfo("ABC.txt");
            try
            {
               
                fi.Open(FileMode.Open);
                int len = (int)fi.Length; // 파일의 크기 !! 

            }
            // 상위타입의 Exception일수록 아래에 구현하자 !! 
            catch (IOException ie)
            {
                Console.WriteLine(ie.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            // finally :   try ~catch 구문이 끝난후 반드시 실행되어야하는 코드들이다 !!
            //  Try ~catch에서의 실행결과에 관계 없이 무조건 실해되어야 하는 코드들 !!! 
            // catch 블록이 존재하는 finally보다 먼저 실행된다 !! 
           // try~catch에서 발생한 리소스들의 정리 작업을  finally에서 수행한다 !! 
            finally
            {
                fi.Delete(); 
            }
        }
    }
}

'C#' 카테고리의 다른 글

[C#] 인덱서  (0) 2014.11.18
[C#] 이벤트  (0) 2014.11.18
[C#] 생성자  (0) 2014.11.18
[C#] 상속  (0) 2014.11.18
[C#] 배열  (0) 2014.11.18
반응형
using System;
using System.Collections.Generic;
using System.Text;

namespace 생성자
{
    class Person
    {
        private string name; 
        public Person()
        {
            Console.WriteLine("Person()");
        }
        public Person(string name)
        {
            Console.WriteLine(name); 
        }
    }
    class BitStudent : Person
    {   
        // C# 생성자 :  객체 초기화하는 함수 !!  
        // 1) 인스턴스 생성자 : 객체가 만들어질때 불려지는 생성자 !!
        public static string InstructorName;  
        public BitStudent()
        {
            Console.WriteLine("BitStudent()");
          
        }
        //2) 정적 생성자 :  static 생성자 !! 
        //  클래스가 메모리에 로딩될때 호출되어지는 생성자 !!
        // --> 무조건 1번만 호출이 된다 !! 
        static BitStudent()
        {   // 스태틱 멤버에 대한 초기화 !! 
            InstructorName = "Jang";
        }

        // base: C#에서 부모 클래스를 의미한다 !!    
        // this() :  자기 클래스의 다른 생성자를 의미한다 !! 
        public BitStudent(string name) : this()
        {
          //  this.name = name; 
            Console.WriteLine(name);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
          // BitStudent bit = new BitStudent("홍길동");
            Console.WriteLine(BitStudent.InstructorName);
        }
    } 


}

'C#' 카테고리의 다른 글

[C#] 이벤트  (0) 2014.11.18
[C#] 예외처리  (0) 2014.11.18
[C#] 상속  (0) 2014.11.18
[C#] 배열  (0) 2014.11.18
[C#] 델리게이트 (Delegate)  (0) 2014.11.18
반응형
using System;
using System.Collections.Generic;
using System.Text;

// 상속  : 부모로부터 코드를 그대로 물려 받는것 ( 구현 상속)  
// is - a :  사람은 동물이다. 버스는 자동차다.    
// 정적생성자.소멸자 멤버 변수들 멤버 함수들... 



namespace AAA
{
    class Shape
    {
        private int x; //  자기 자신에서만 접근 가능 !! 
        public int y; //  어디서든 접근이 가능 !! 
        protected int z; // 자신이랑 자식에서만가능 !! 
        internal int Q;  // 같은 어셈블리 -> 같은 프로젝트안에서만 

        void Draw()
        {
            x = 10;
            y = 10;
            z = 30;
            Q = 40;
        }

    }
    class Window
    {

    }
    // C++에서는 여러개의 클래스로 부터 상속을 받는 다중상속이 가능했지만. 
    // C#에서는 1개의 클래스로부터 상속이 가능하다.;;
    // sealed : 더이상 상속을 시켜고 싶지 않을때!!
    // 마지막 파생 클래스임을 의미한다 !! 
   sealed class Rect : Shape
    {
        void Draw1()
        {
            x = 10;
            y = 20;
            z = 30;
            Q = 40;
        }
    }
   class RoundRect : Rect 
   { 
   
   }
        

}


namespace 상속
{
 


    class Program
    {
        static void Main(string[] args)
        {
            AAA.Shape s = new AAA.Shape();
            s.x = 10;
            s.y = 20;
            s.z = 30;
            s.Q = 40; 
        }
    }
}

'C#' 카테고리의 다른 글

[C#] 예외처리  (0) 2014.11.18
[C#] 생성자  (0) 2014.11.18
[C#] 배열  (0) 2014.11.18
[C#] 델리게이트 (Delegate)  (0) 2014.11.18
[C#] C#에서 제공하는 기본 타입들  (0) 2014.11.18
반응형
using System;
using System.Collections.Generic;
using System.Text; 

namespace 배열
{
    class Program
    {
        static void Main(string[] args)
        {
//*******************************************************************************
            // 배열 
//*******************************************************************************
           //  C언어 배열 -> 정적 배열 , heap동적배열 
            //  C#의 배열은 무조건 heap에 할당되는 동적 배열이다 !! 
            // 1) 배열의 특징 
             /*   - 인덱스를 통한 접근( 인덱스는 0부터...) 
              *   - 모든 요소를 같은 타입의 데이터  
              *   -  참조형 타입이다 !! 
              *   -  System.Array추상클래스의 인스턴스이다 !! 
              */
            // 배열의 선언 !!
         // C언어 스타일 --->    int p[10];
         // C#배열 -->  타입 []  배열이름; 
          //  int[] intArray; 
          //   intArray[0] = 10; -->  C#배열은 기본 동적배열 !! 

         //   int size = 10; 
        //    int []  pArray =  new int[size]; // 변수값 사용가능 !! 
            // 배열을 선언과 동시에 초기화하기 !! 
           /* int[] data1 = new int[] { 0, 1, 2, 3, 4 };
            int[] data2 = new int[5] { 0, 1, 2, 3, 4 };
            int[] data3 = { 0, 1, 2, 3, 4 }; */
            // 형변환 !!
            //    atoi ,  itoa :  tostring() ,  int.parse() 
          //  int Size = int.Parse( Console.Read().ToString()); 
        //    int[] data4 = new int[Size];
/*
            foreach (var item in collection)
            {
                
            }

           for (int i = 0; i < 10; i++)
			{
                Console.Write("[ {0} ]", item);
            }
            */ 
            // 다차원 배열 
            //int[,] data; // 2차원 배열 
    //        int[, ,] data1; // 3
    //       int[, , ,] data2; //4 
            /*
            int[,] data = new int[ , ] { { 0, 1, 2 }, { 3, 4, 5 } };
            int[,] data1 =  { { 0, 1, 2 }, { 3, 4, 5 } };

            foreach (int i in data1)
            {
                Console.WriteLine(i);
            }
            data1[0, 0] = 10; //인덱스를 통한 접근 !! 
            foreach (int i in data1)
            {
                Console.WriteLine(i);
            }
            */ 
            // 가변 배열 --> 서로 다른 차원의 크기를 갖을수 있는 배열의 배열 
            /*
            int [][] data =  new int[3][];
            data[0] = new int[5];
            data[1] = new int[3];
            data[2] = new int[10];

            foreach (int [] i in data)
            {
                foreach (int ii in  i)
                {
                    Console.Write(ii);
                }
                Console.WriteLine("");
            }
             */ 
            // System.Array 클래스와 사용 !! 

            int[] data = { 10, 5, 15, 24, 30, 22 };

          

            for (int i = 0; i < data.Length ; i++)
			{
                Console.Write(data[i]);
			}
            Console.WriteLine("");
            //Array.Clear( data, 0, data.Length);
           // Array.Sort(data);
          //  Array.Reverse(data);
            Console.WriteLine(  Array.Find( data, 10)) ; 
            for (int i = 0; i < data.Length; i++)
            {
                Console.Write(data[i]);
            }

           




        }
    }
}

'C#' 카테고리의 다른 글

[C#] 생성자  (0) 2014.11.18
[C#] 상속  (0) 2014.11.18
[C#] 델리게이트 (Delegate)  (0) 2014.11.18
[C#] C#에서 제공하는 기본 타입들  (0) 2014.11.18
[C#] C# 언어의 특징  (0) 2014.11.18
반응형
using System;
using System.Collections.Generic;
using System.Text;

// 델리게이트  
// C/C++에서 사용된 함수포인터 !! 
// C#에서는 포인터 개념을 사용하지 않기때문에 .. 
//  메소드에 대한 참조를 델리게이트 !!
// 이벤트 처리기 -->  콜백함수  
// --> 실행 시간에 동적으로 호출할 메서드 처리를 위해  사용 !!! 
//  함수포인터와 델리게이트의 차이점 !! 
// --> 대리자는 객체 !! 
// --> 동적바인딩을 위해 지원한다 !!  
//  동적 바인딩 ?? 
// 실행시간에 어떤 함수가 호출되어야 할지를 결정하는 기법 !! 


namespace 델리게이트
{
    class Program
    {
        // 1. static 메소드 
        // 2. 인스턴스 메소드 
        // 3. 다른 딜리게이트 
        public delegate void MyDelegate();

        static   public void foo() 
        {
            Console.WriteLine("foo() ");
        }
        static public void  goo()
        {
            Console.WriteLine("goo() ");
        } 

        static void Main(string[] args)
        {
           MyDelegate md; 
           Random rand =  new Random(2);
           for (int i = 0; i < 10; i++)
           {
               if ((rand.Next() % 2) == 0)
                   md = new MyDelegate(Program.foo);
               else
                   md = new MyDelegate(Program.goo);

               md();
           }
        }
    }
}

'C#' 카테고리의 다른 글

[C#] 상속  (0) 2014.11.18
[C#] 배열  (0) 2014.11.18
[C#] C#에서 제공하는 기본 타입들  (0) 2014.11.18
[C#] C# 언어의 특징  (0) 2014.11.18
[C#] C# 객체 지향 프로그래밍!!  (0) 2014.11.18

+ Recent posts