.NET/C# Basic
-
인터페이스(interface) 와 추상화클래스(abstract) 예제.NET/C# Basic 2008. 10. 14. 17:03
using System; namespace test_cal { interface IAdd { int Add(int i, int j); } interface IMnus { int Minus(int i, int j); } abstract class abMethod { public int Add(int i , int j) { int tot = i +j; return tot; } public abstract int Minus(int i ,int j); } class NewabMethod : abMethod { public override int Minus(int i, int j) { int m = i -j; return m; } } class NewInter : IAdd, IMnus { public int Ad..
-
C# Delegate와 Event 중요.NET/C# Basic 2008. 10. 13. 14:07
모르겠으니까 예제 외우자 낄낄낄~~~!!! [8.Delegate와 Event예제 \ delegate.cs] using System; class MainApp { public delegate void Mix(string s); // 델리게이트 선언 public static void Coffee(string s) { Console.WriteLine("this Coffee is Mixed with {0} ", s); } public static void CoCoa(string s) { Console.WriteLine("this CoCoa is Mixed with {0} ", s); } public static void Main() { Mix Tea = new Mix(Coffee); //할당된 델리게이트는 Co..
-
Console.Read() 와 Console.ReadLine() 차이.NET/C# Basic 2008. 10. 10. 20:12
using System; class whileTest { public static void Main() { bool ugiy = false; bool fool = false; Console.WriteLine("정신 교정 프로그램"); while (!(ugiy && fool)) { Console.WriteLine("당신은 잘생겼습니까? y/n"); if(Console.ReadLine() == "n") //
-
흐름 제어 예제 기본문법 if for while swich foreach break continue.NET/C# Basic 2008. 10. 10. 20:11
using System; class GenderTest { public static void Main() { Console.WriteLine("아유보이? (y)/(n)"); char gender = (char)Console.Read(); if( gender == 'y') Console.WriteLine("남자이시군요"); else if (gender == 'n') Console.WriteLine("여자이시군요"); else Console.WriteLine("잘못된 성별을 입력하셨습니다"); } } using System; class cyon { public static void Main() { Console.WriteLine("요일을 입력하세요"); char day = (char)Console.Read(..
-
연산자 오버로딩 - 인덱스.NET/C# Basic 2008. 10. 10. 17:27
class Point { public int x; public int y; public Point(int x, int y) { this.x = x; this.y = y; } public override string ToString() { //(x,y)값 return String.Format("({0},{1})",x,y); } // + 연산자 메서드 public static Point operator +(Point pt1, Point pt2) { return (new Point(pt1.x + pt2.x, pt1.y + pt2.y)); } // - 연산자 메서드 public static Point operator -(Point pt1, Point pt2) { return (new Point(pt1.x - p..
-
C# 사용 개념 대충 순서 대충보는거 대충.NET/C# Basic 2008. 10. 10. 14:40
///////////////////////////////// 콘솔 ////////////////////////////////////// using System; using System.Collections.Generic; using System.Text; using Calculator; // 추가~~~ namespace ConsoleApplication37 { class Program { static void Main(string[] args) { int i = int.Parse(Console.ReadLine()); int j = int.Parse(Console.ReadLine()); Cal c1 = new Cal(); int k = c1.Add(i,j); int o = c1.Minus(i,j); } }..
-
C# 정정맴버.NET/C# Basic 2008. 10. 10. 14:37
정적 메서드 메서드에도 정적(static)으로 적용할 수 있다 정적 메서드는 주로 정적 데이터 멤버를 다룰 때 사용 public static string GetInstCount() { // 정적(static) 데이터를 다룬다. } 정적 메서드에서는 인스턴스(instance)를 다룰 수 없기 때문에 다음과 같은 몇 가지 제약이 있정적 멤버만 사용할 수 있고, 인스턴스 변수나 메서드는 사용할 수 없다. 정적 메서드에서 this 키워드를 쓸 수 없다 인스턴스 메서드에서는 인스턴스 멤버와 정적 멤버를 둘 다 사용할 수 있다 정적 멤버는 클래스에 하나만 정의되는 멤버로, 모든 인스턴스에서 공유되는 멤버 class Point { // 생성자 정의 public Point() { nInstance++; // 인스턴스 ..
-
클래스 관련 예제.NET/C# Basic 2008. 10. 10. 02:25
//////// 우리가 이런예제를 보고 따라치면 자동으로 코딩도하면서 이해가되지요~ 책보다는쉽게합시다 //////// using System; class Profile { private int Age = 23; private string Name = "전광식"; private string Phone = "333-5765"; public void PrintInfo() { Console.WriteLine("{0}",Name); Console.WriteLine("{0}",Age); Console.WriteLine("{0}",Phone); } } class Access { public static void Main() { Profile my = new Profile(); my.PrintInfo(); } } us..
-
상봉이 문제.NET/C# Basic 2008. 10. 9. 14:05
배경 컴퓨터 과학에서 문제들은 종종 불분명한 문제들에 속하거나 분류된다. (풀리지 않은 문제, 풀수 없는 문제, 순환되는 문제) 이 문제에서는 누군가 체계화 하여 가능한 모든 입력에 대한 결과가 알려지지 않은 algorithm의 특성을 분석할것이다. 문제 다음 algorithm을 따라서 풀어보라. ================================ 1.input n 2.print n 3.if n=1 then STOP 4.if n is 홀수 then n을 3n+1로 바꾼다. 5.else n을 n/2로 바꾼다. 6.위의 2번으로 돌아가서 반복한다. ================================ 만약 n을 22로 입력하면 22 11 34 17 52 26 13 40 20 10 5 16 8 4..
-
정적맴버의 이해 인스턴스.NET/C# Basic 2008. 10. 8. 17:35
using System; // 정적 class Point { public Point() { nlnstance++; //Console.WriteLine("{0}",Point.nlnstance);//static변수값누적 Console.WriteLine("{0}",this.nlnstance);// 인스턴스변수누적안됨 } // public static int nlnstance =0; // static 를 없해고 함 public int nlnstance = 0; } class Class1 { static void Main() { // Console.WriteLine("{0}",Point.nlnstance); // 정적인것 Point obj1= new Point(); Point obj2= new Point(); P..
-
C# 메서드.NET/C# Basic 2008. 10. 7. 17:06
/*메서드 C# 메서드는 리턴형, 메서드 이름, 메서드 인자로 구성 메서드 구현 코드는 메서드 선언 부분 다음에 위치하며, return 문은 메서드를 종료하고 결과 값을 리턴할 때 사용 * * using System; class Test { // 메서드 정의 public static int Max( int v1, int v2 ) { // 인자 값 비교 후, 큰 값을 리턴합니다. return ( v1 < v2 ) ? v2 : v1; } static void Main() { // 메서드 부르기 Console.WriteLine( "MAX(100,200) : {0}", Max( 100, 200 ) ); // 200 } } * using System; class Test { // 메서드 정의 public int ..
-
C# 배열 연산자 제어문 foreach.NET/C# Basic 2008. 10. 6. 15:21
배열 array int [] array; array = new int [5]; for ( int i=0; i< array.Length; i++ ) { array[i] = i; // 0 ~ 4 } 다차원 배열 // 2 차원 배열 선언 int[,] array; // 배열에메모리 할당 array = new int [3,3]; // 배열에값 할당, 인덱스 범위 array [0..2, 0..2] array[0,0] = 100; int value = array[0,0]; 길이가 다른 다차원 배열 2차원 배열의 경우 다음과 같이 선언 int[][] array; // 2차원 배열 선언 각 열마다 사용하는 요소 개수가 다른 경우이기때문에 필요한 만큼 메모리를 할당 array = new int[2][]; 각 열마다 갖는 ..
-
-
상철이 소스.NET/C# Basic 2008. 10. 2. 17:34
using System; using System.Collections.Generic; using System.Text; using System.Data; namespace gugudan { class Program { static void Main(string[] args) { int[] value1 = new int[9] {1,2,3,4,5,6,7,8,9}; int[,] value2 = new int[9, 9]; try { for (int i = 1; i < 9; i++) { Console.WriteLine("{0}단", value1[i]); for (int j = 0; j < 9; j++) { value2[i, j] = value1[i] * value1[j]; Console.WriteLine("{0}..
-
-
-
-
-
-
프로퍼티 관련소스.NET/C# Basic 2008. 10. 1. 21:30
using System; using System.Collections.Generic; using System.Text; namespace pt1 { class Point1 { public int a; public int b; public Point1(int a,int b) { this.a = a; this.b = b; } } class Point2 { private int aa; private int bb; public void set(int aa,int bb) { this.aa = aa; this.bb = bb; } public int getaa() { return aa; } public int getbb() { return bb; } } class Point3 { private int xx; priv..
-
프로퍼티 설명 get/set.NET/C# Basic 2008. 10. 1. 19:43
아래 관련소스 2개중 한개는 인터넷에긁어왔고 나머지하나는 권오윤양소스입니다 소스만 보셔도 대충 이해되실꺼에염~!!! 프로퍼티를 설명하기전에 클래스를 보면 클래스는 엑세스 지정자라는 것을 통해 중요한 맴버를 외부로 부터 보호할수있죠 만약 모든 맴버를 외부에서 마음대로 릭고 쓸수 있다면 규칙에 맞지 않는 값이 들어올수 있어 객체의 무결성!!! 이 파괴 될것이라고하더군요~! 무결성이 훼손된 객체는 제대로 동작하지도 않을 뿐더러 언제 말썽을 일으킬지 알수없으므로 무척위험하답니다 그래서 프로퍼티get/set 을 쓰는것같군요 private는 함부로 읽거나 쓰지 못하도록 금지한겁니다 대신 공개된 get/set 메서드를 제공하지요~!!! 위에서스를 보면 대충 ~~ 요런거 public int XXX { get/set }..
-
프로퍼티 예제.NET/C# Basic 2008. 10. 1. 18:20
인터넷에서 긁어왔습니다 using System; class GAME { private string strTitle; private string strGenre; public string Title { get { Console.WriteLine("Title 프로퍼티의 get 호출"); return strTitle; } set { Console.WriteLine("Title 프로퍼티의 set 호출"); strTitle = value; } } public string Genre { get { Console.WriteLine("Genre 프로퍼티의 get 호출"); return strGenre; } set { Console.WriteLine("Genre 프로퍼티의 set 호출"); strGenre = value..
-
-
클래스 멥버 관련소스.NET/C# Basic 2008. 10. 1. 16:36
using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication3 { class Point { private int x; private int y; public void SetPoint(int ax, int ay) { x = ax; y = ay; } public void showPoint() { Console.WriteLine("(x,y) = ({0}, {1})", x, y); } } class Class1 { static void Main() { Point pt = new Point(); pt.SetPoint(100, 200); pt.showPoint(); } } } ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ
-