본문 바로가기

반응형

C Sharp

(26)
C# File Read, Write, 파일 입출력 예제 > 파일 쓰기C드라이브 Temp 폴더에 Temp.txt를 쓴다고 할경우 string Target_path = @"c:\Temp\Temp.txt"; System.IO.FileStream file_stream = new FileStream(Target_path, FileMode.Create, FileAccess.Write);StreamWriter psWriter = new StreamWriter(file_stream, System.Text.Encoding.Default);string ko_html = "test";psWriter.WriteLine(ko_html);psWriter.Close(); > 파일 읽기string f_name = @"C:\temp\Temp.txt"; System.IO.StreamRead..
C# DateTime 예제 C# DateTime 예제 //그달의 1일DateTime firstDayOfMonth = System.DateTime.Parse(DateTime.Now.ToString("yyyy-MM-01")); // 그달의 마지막날string lastDayOfMonth = firstDayOfMonth.AddMonths(1).AddDays(-1); // 오늘 날짜DateTime today = DateTime.Today; // 1일 날짜를 가져오는 방법DateTime first_day = today.AddDays(1 - today.Day); // 이번달의 1일날DateTime first_day = today.AddDays(1 - today.DayOfYear); // 첫번째 주의 일요일을 가져오는 방법DateTime fir..
C# List 사용예제. C# Collections.Generic - 2. C# List 사용예제. C# Collection - 2. IDE : Microsoft Visual Studio 2005 static void Main(string[] args) { List list = new List(); list.Add("c"); list.Add("d"); list.Add("b"); list.Sort(); foreach(object obj in list) { Console.Write("{0}\n",obj); } list.Reverse(); int nTemp = 5 if(list.Count > nTemp) { int nDelCnt = list.Count - nTemp; int i =0; while (i < nDelCnt) { list.RemoveAt(0); i++; } } object..
C# Dictionary 사용 예제. C# Collections.Generic - 1. C# Dictionary 사용 예제 Dictionary _DicSample;_DicSample= new Dictionary();_DicSample.Add( "나이", 32 );_DicSample.Add( "키", 180 ); foreach (KeyValuePair each in _DicSample){string K = each.Key;int V = each.Value;}// 디버깅 해보면 foreach문이 2번돌고 K,V값에는 {"나이", 32},{"키",180} 이 순차적으로 들어간다. Key값을 알고있을때 Value값 찾는건 map과 동일한int age = _DicSample["나이"];// age에 32가 들어갈것이다.. //키값이 있는지 확인_DicSample.ContainsKey("키값"); /..
C#, TEXTBOX 숫자만 입력받기 C#, TEXTBOX 숫자만 입력받기 private void textBox1_TextChanged(object sender, EventArgs e){ TextBox textBox = sender as TextBox; Int32 selectionStart = textBox.SelectionStart; Int32 selectionLength = textBox.SelectionLength; String newText = String.Empty; foreach (Char c in textBox.Text.ToCharArray()) { if (Char.IsDigit(c) || Char.IsControl(c)) newText += c; } textBox.Text = newText; textBox.SelectionSt..
C# EUCKR, UTF-8 변환 C# EUCKR, UTF-8 변환 방법 using System;using System.Collections.Generic;using System.Linq;using System.Text; namespace Encoding{ class Program { static void Main(string[] args) { string s = "홍길동"; Console.WriteLine("원본문자열 : {0}", s); // 코드페이지 번호 : http://msdn.microsoft.com/ko-kr/library/system.text.encoding.aspx int euckrCodepage = 51949; // 인코딩을 편리하게 해주기 위해서 인코딩클래스 변수를 만듭니다. System.Text.Encoding ut..
C#, Stringformat, 숫자표시 포맷, 통화표시 //헥사코드 디버깅 할일 있을때 16진수 코드 찍기String.Format("{0:X}", Convert.ToInt32(letter)); //소수점 두자리 표시String.Format("{0:0.00}", 123.4567); // "123.46"String.Format("{0:0.00}", 123.4); // "123.40"String.Format("{0:0.00}", 123.0); // "123.00" //소수가 있으면 있는 자리만큼만 표시,없으면 자리 표시 무시String.Format("{0:0.##}", 123.4567); // "123.46"String.Format("{0:0.##}", 123.4); // "123.4"String.Format("{0:0.##}", 123.0); // "123" /..
C#, Thread.sleep 대신 사용하기 좋은 함수 Delay [펌]Thread.sleep 쓰면 일반적인 용도로 대기 시간 주기에는 폼이 멈춰서 불편하다.화면이 멈추지 않고 딜레이를 줄수 있게끔 하는거. private static DateTime Delay(int MS){DateTime ThisMoment = DateTime.Now;TimeSpan duration = new TimeSpan(0, 0, 0, 0, MS);DateTime AfterWards = ThisMoment.Add(duration);while (AfterWards >= ThisMoment){System.Windows.Forms.Application.DoEvents();ThisMoment = DateTime.Now;}return DateTime.Now;} 별도의 라이선스 관련 표시가 없어서 원본의 ..

반응형