본문 바로가기

.NET/C#

(75)
C# Universal String Parsing Utility http://www.codeproject.com/Tips/434173/Csharp-Universal-String-Parsing-Utility 위에서 퍼온 글입니다. The ProblemtryParse()을 이용해서 string 을 다른 타입으로 파싱하는 일은 참 나를 고통으로 몰고 있다. 그리고 결과코드도 지저분하다. var someStringThatShouldBeAnInt = "10"; int i = 0; if(int.TryParse(someStringThatShouldBeAnInt, out i)) { //Continue on with things }else { //Complain about it } The Desired Solution지저분한것들을 추상화하고 그것을 아래와같이 대체한다.: var so..
c# 천자리 단위 콤마 넣기 String.Format("{0:n}", 1234); number.ToString("#,##0"); string.Format("{0:#,#}", num) function GetNumberWithQ(Price) { var myNumber = Price.toString(); // Price Is Your Namber Your Number var myResult = ""; for (var i = myNumber.length - 1; i >= 0; i--) { myResult = myNumber[i] + myResult; if ((myNumber.length - i) % 3 == 0 & i > 0) myResult = "," + myResult; } return myResult; }
c#으로 BHO(Browser Helper Object) 만들기 http://www.codeproject.com/Articles/350432/BHO-Development-using-managed-code 위에서 퍼온 글입니다. Introduction Browser Helper Object (BHO) is a plug-in for Internet Explorer (IE). BHO let developers to drive IE. A plug-in is a program which extends the functionality of a browser. It can be used to retrieve information or modify the content of the webpage that is being displayed in a browser window, or ..
컴퓨터에서 실행되는 프로세스중에 닷넷 어플리케이션인것 찾기 http://blog.naver.com/techshare/100151470787 이에 대해서는, 어려운 방법을 쓰려면 한없이 어려워지겠지만 간단하게 생각하면 그다지 어렵지 않습니다. 쉽게 생각해 볼까요? ^^ 현재 대표적으로 .NET 2.0 과 .NET 4.0 유형이 있으니, 이들을 실행해보고 "Process Explorer" 같은 도구를 이용하여 공통적으로 올라오는 DLL 을 확인해 볼 수 있습니다. 결과는 다음과 같습니다. .NET 4.0 mscoree.dllmscoreei.dllclr.dllclrjit.dll .NET 2.0 mscoree.dllmscorjit.dllmscorwks.dll mscoree.dll 파일이 중복되는 군요. 그런데, 테스트를 하다 보니 mscoree.dll 까지만 올라오고 ..
C# - 원본 파일의 공백/라인을 유지한 체 XML 파일을 저장하는 방법 http://blog.naver.com/techshare/100151160015 위의 글에서 퍼온겁니다. 아는 분과 이야기를 하다가, 그 분은 XML 파일로 설정 저장을 하는 것이 싫어서 "Key=Value" 형식의 포맷으로 저장하는 간단한 라이브러리를 사용한다고 하십니다. ^^ XML 이 싫은 이유인 즉, 저장하면서 기존 파일에 있던 공백/라인 형식이 모두 제거되고 다시 정렬되기 때문이라고 했습니다. 아하~~~ 아직도 모르고 계셨군요. ^^ 예를 들어, 다음과 같은 문서를 로드한 경우, 1 XmlDocument 로 Load/Save 를 하면 기본적으로는 다음과 같이 저장됩니다. 5 사용자가 멋있게(?) 포맷팅 해 둔 텍스트 파일의 형식이 날아가 버린 것입니다. 이를 방지하려면 다음과 같이 Load 이전..
supportedRuntime 옵션과 System.BadImageFormatExceptionsupportedRuntime 옵션과 System.BadImageFormatException [출처] supportedRuntime 옵션과 System.BadImageFormatException 예외|작성자 techshare supportedRuntime 옵션과 System.BadImageF.. http://blog.naver.com/techshare/100151158445 위의 글을 퍼온겁니다. 최근에 다음과 같은 오류를 만났습니다. Unhandled Exception: System.BadImageFormatException: Could not load file or assembly 'ConsoleApplication1.exe' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. File name: 'ConsoleApplication1.exe' 머리로는 BadImageFormatException 이 x86/x64 의 불일치..
Mail보낼때 이미지 삽입하기 MailMessage Mail = new MailMessage(); Mail.From = new MailAddress("balaji.birajdar@bogusdomain.com"); Mail.To.Add("balaji.birajdar@bogusdomain.com"); Mail.Subject = "This is Image Test."; Mail.Body = "This is the body of the email"; LinkedResource LinkedImage = new LinkedResource(@"J:\My Documents\Advika1.jpg"); LinkedImage.ContentId = "MyPic"; AlternateView htmlView = AlternateView.CreateAltern..
해당 어셈블리가 Debug 빌드인지, Release 빌드인지 알아내는 방법 http://blog.naver.com/techshare/100150127754 위에서 퍼온 글입니다. 국내는 어떤지 모르겠지만, 해외의 경우에는 '서비스 중인 DLL'이 Debug 빌드된 것인지, Release 빌드된 것인지를 민감하게 여기는 경우가 있는 것 같습니다. 필요없이 성능에 손해되는 DLL 로 서비스할 이유는 없으니까요. 검색을 해보면, 생각보다 쉽게 방법을 찾을 수 있습니다. How to tell if a .NET application was compiled in DEBUG or RELEASE mode? ; http://stackoverflow.com/questions/194616/how-to-tell-if-a-net-application-was-compiled-in-debug-or-rel..