Blog Content

  • 36.C# - 스택 (Stack)

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

    스택이란 데이터 저장시 LIFO(Last In First Out)개념을 추가해서 저장합니다. 사용 용도로는 보통 웹브라우저의 뒤로가기, 앞으로 가기 기능입니다. (그림 클릭시 원본크기) using System; using System.Collections; //모든 컬렉션(Collection)관련 네임스페이스 public class 스택 { public static void Main(string[] args) { //[1] Stack 클래스의 인스턴스 생성 Stack visits = new Stack(); //[2] 저장 Push(메서드) : 스택에 데이터 입력할 대 visits.Push("야후"); visits.Push("네이버"); visits.Push("닷넷코리아"); //[3] 출력 : Pop()..

    Read more
  • 35.C# - StringBuilder (스트링빌더)

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

    String은 값을 변경 못하며 읽기 전용으로 사용되고, StringBuilder는 변경 가능합니다. String는 System.Text.StringBuilder로 네임스페이스(namespace)로 사용가능합니다. msdn - StringBuilder msdn - String Class using System; using System.Text; public class 스트링빌더 { public static void Main(string[] args) { //[1] 문자열 저장 string s = "안녕하세요."; string ss = "반갑습니다."; //[2] 긴 문자열 저장 int row = 3; int col = 3; // 3행 3열 테이블 태그 생성 StringBuilder sb = new Str..

    Read more
  • 09.C# - 알고리즘 : 정렬(Sort)

    Category C# on 2009. 8. 7. 21:31

    정렬(Sort)-순서대로 정렬시키는 알고리즘으로 오름차순과 내림차순이 있습니다. 오름차순(Ascending)정렬 : 1,2,3 ABC순 내림차순(Desending)정렬 : 3,2,1 다나가 순 종류로는 : 선택정렬, 버블정렬, 퀵정렬, 삽입, 기수등이 있습니다. using System; public class 선택정렬 { public static void Main() { //[1] Input int[] data = { 7, 5, 6 }; //[2] Process int temp = 0; for (int i = 0; i data[j]) { temp = dat..

    Read more
  • 08.C# - 알고리즘 : 순위 Rank

    Category C# on 2009. 8. 7. 21:13

    주어진 범위 안에서 순위를 구하는 알고리즘입니다. 순위 배열을 1등으로 값을 초기화 한 후 초기값 보다 큰 값이 나오면 1씩 증가시켜서 결과값을 구하는 예제 입니다. http://blog.naver.com/min9888596 [멍멍님 블로그] using System; public class 순위 { public static void Main(string[] args) { //[1] Input int[] score = { 90, 87, 100, 95, 80, 34 }; int[] rank = { 1, 1, 1, 1, 1, 1 }; //[2] Process for (int i = 0; i < score.Length; i++) { for (int j = 0; j < score.Length; j++) { //비..

    Read more
  • 34.C# - Random 클래스

    Category C# on 2009. 8. 7. 20:52

    Random 클래스는 랜덤으로 수를 만들어 낼 수 있어 암호화 또는, 게임,회원가입에서 많이 사용됩니다. 기본예제 using System; public class 랜덤클래스 { public static void Main() { //임의의 수 출력 //Random 클래스의 인스턴스 생성 Random r = new Random(); for (int i = 0; i < 10; i++) { Console.WriteLine("{0}",r.Next(20)); } } } 응용예제1 - 1~45 까지의 수를 6개 랜덤으로 출력하기 ( Random 클래스로 로또 만들기 ) Random ran = new Random(); int[] arr = new int[6]; // 6개 데이터 int temp = 0; for (int..

    Read more
  • 33.C# - 시스템 환경변수관련 Environment 클래스

    Category C# on 2009. 8. 7. 20:13

    Environment 클래스는 컴퓨터의 여러가지 정보를 확인 할 수 있습니다. (폴더 경로, 컴퓨터관련 정보, 프로그램 버전 정보등) using System; public class 환경변수 { public static void Main() { Console.WriteLine(Environment.SystemDirectory); //시스템폴더 Console.WriteLine(Environment.Version); //닷넷버전 : 2.0.50727 Console.WriteLine(Environment.OSVersion); //운영체제 버전 Console.WriteLine(Environment.MachineName); //컴퓨터 이름 Console.WriteLine(Environment.UserName); ..

    Read more
  • 32.C# - Math.Round 메서드 사용 예제

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

    값을 가장 가까운 정수나 지정된 소수 자릿수로 반올림 하는 예제입니다. using System; public class 반올림 { public static void Main() { double d = 1234.5678; Console.WriteLine(Math.Round(d,2)); //1234.57 Console.WriteLine(); Console.WriteLine(MyRound(d, 2)); //1234.57 Console.WriteLine(); double temp = (int)((d + 0.005)*10)/100.0; //XXX.XX Console.WriteLine("{0}",temp); } //정수형으로 자리수 포지션을 잡아서 반올림 public static double MyRound(doub..

    Read more
  • 31.C# - Math 클래스의 메서드 및 속성

    Category C# on 2009. 8. 7. 19:27

    Math 는 삼각, 로그 및 일반 수학 함수에 대한 상수 및 정적 메서드를 제공합니다 using System; public class 수학관련함수확장 { public static void Main() { Console.WriteLine(Math.E); //자연로그 Console.WriteLine(Math.PI); //3.1415926535 Console.WriteLine(Math.Abs(-10)); //절대값 Console.WriteLine(Math.Pow(2,10)); //2^10 = 1024 Console.WriteLine(Math.Round(1234.5678,2)); //1234.57 Console.WriteLine(Math.Max(3,5)); //5 Console.WriteLine(Math.Min..

    Read more
  • 30.C# - String Class의 Format Method

    Category C# on 2009. 8. 7. 19:10

    지정된 String의 형식 항목을 해당 개체의 값에 맞는 텍스트 또는, 정의된 형식으로 바꿔줄 수 있습니다. using System; public class 스트링포맷 { public static void Main(string[] args) { int i = 1234; double d = 1234.5678; string s = "1234"; //서로 다른 데이터형식을 묶을 때 문자열로 묶어준다. string result = String.Format("{0} {1} {2}", i, d, s); Console.WriteLine("{0}", result); //정수 또는 실수형 자릿수 표현 가능 result = String.Format("{0:###,###}",i); Console.WriteLine(resul..

    Read more
  • 29.C# - String Class의 중요 메서드

    Category C# on 2009. 8. 7. 18:34

    전체 경로가 입력되었을 때 파일명과 확장자 추출 예제입니다. using System; public class 파일명추출 { //전체 경로가 입력되었을 때 파일명과 확장자 추출 public static void Main(string[] args) { string dir = "c:\\Website\\redPlus\\Images\\test.gif"; string fullName = String.Empty; string name = ""; string ext = name; //전체 파일명 : test.gif fullName = dir.Substring(dir.LastIndexOf('\\') + 1); //순수 파일명 : test name = fullName.Substring(0, fullName.LastInde..

    Read more
  • 28.C# - StringClass -2-

    Category C# on 2009. 8. 7. 18:14

    StringClass를 이용한 방법 입니다. 특정 문자열을 뽑아 내거나 검사하는 예제 입니다. using System; public class 스트링클래스2 { public static void Main(string[] args) { string s = string.Empty; //빈문자열 저장 s = ""; //일반적으로 많이 쓰는 표현 s = " Abc Def Fed Cba "; //테스트용 문자열 저장 //구분자(공백, 콤마)를 사용해서 분리해서 저장 string[] arr = s.Trim().Split(' '); //??? //arr[0]="Abc"; //arr[1]="Def"; //arr[2]="Fed"; //arr[3]="Cba"; foreach (string item in arr) { Con..

    Read more
  • 27.C# - StringClass (스트링클래스)

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

    String Class는 문자열 클래스로 문자열에 관한 다양한 메서드를 제공하고 있습니다. 예제1 using System; public class 스트링클래스 { public static void Main(string[] args) { string s = string.Empty; //빈문자열 저장 s = "" ; //일반적으로 많이 쓰는 표현 s = " Abc Def Fed Cha "; //테스트용 문자열 저장 Console.WriteLine("{0}", s); //전체출력 //인덱스 이용한 문자 출력 Console.WriteLine(s[6]); Console.WriteLine(s[6-1]); //6번째 인덱스에서 -1 또는, +1 가능 Console.WriteLine(s[6+1]); Console.Wr..

    Read more
  • 07.C# - 알고리즘 : 수열 구하기

    Category C# on 2009. 8. 6. 21:37

    예제1 : 1 - 2 + 3 - 4 + 5 ... +99 - 100 = ? 구하기 using System; public class 간단수열 { public static void Main(string[] args) { int total = 0; for (int i = 1; i

    Read more
  • 06.C# - 알고리즘 : 최빈값 (가장 많이 나타낸 값)

    Category C# on 2009. 8. 6. 21:13

    최빈값(가장 많이 나타낸 값)을 구하는 예제입니다. //최빈값(MODE) : 가장 많이 나타난 값 // -> 데이터의 인덱스(0~100점)의 카운터(COUNT)값의 최대값(MAX) using System; public class 최빈값 { static void Main(string[] args) { int[] score = { 6, 3, 2, 2, 2, 4, 4 }; int mode = 0; //최빈값이 담길 그릇 int[] index = new int[7]; int max = Int32.MinValue; for (int i = 0; i < score.Length; i++) { index[score[i]]++; //count } for (int i = 0; i < index.Length; i++) { i..

    Read more
  • 05.C# - 알고리즘 : 가까운 값 구하기

    Category C# on 2009. 8. 6. 20:26

    변수에 저장된 값과 가장 가까운 배열에 선언된 값을 찾는 예제 입니다. using System; public class 가까운값 { public static void Main(string[] args) { //[1] Input int[] data = { 10, 20, 30, 26, 27, 17 }; int target = 25; // traget과 가까운 값 int near = 0; //가까운값 : 27 int min = Int32.MaxValue; //[2] Process for (int i = 0; i < data.Length; i++) { if (Abs(data[i] - target) < min) { min = Abs(data[i] - target); //최소값 알고리즘 near = data[i];..

    Read more
1 ··· 133 134 135 136 137 138 139 ··· 143