Programming/C#

Programming/C#

Dllimport Path Rule

Before the system searches for a DLL, it checks the following: If a DLL with the same module name is already loaded in memory, the system uses the loaded DLL, no matter which directory it is in. The system does not search for the DLL. If the DLL is on the list of known DLLs for the version of Windows on which the application is running, the system uses its copy of the known DLL (and the known DL..

Programming/C#

Action, Func, Predicate, Task

Action, Func, Predicate 참조 http://www.csharpstudy.com/Tip/Tip-Func.aspx Action, Func, Task 참조 http://devsw.tistory.com/170 7ways to start a Task in .Net http://dotnetcodr.com/2014/01/01/5-ways-to-start-a-task-in-net-c/

Programming/C#

C# Collection conversion to Casted List

아래의 예제는 TreeNodeCollection 을 Podcast List로 변환하는 LINQ 메소드 조합이다. Collection 은 IList 를 IList 는 IEnumerable, ICollection 을 상속함. 따라서 이를 List 인스턴스로 변환하여 return 하는 구성을 갖을 수 있음. var podcasts = subscriptionView.treeViewPodcasts.Nodes .Cast() .Select(tn => tn.Tag) .OfType() .ToList(); Nodes로 부터 Collection 인스턴스를 받고 IEnumerable를 받음 여기에서 Treenode안에 있는 Tag 에 연결된 인스턴스들을 모두 선택하고 PodCast 타입의 IEnumerable 인스턴스를 받아..

Programming/C#

Send Email (Gmail)

// Command line argument must the the SMTP host. SmtpClient client = new SmtpClient(); client.Port = 587; client.Host = "smtp.gmail.com"; client.EnableSsl = true; client.Timeout = 10000; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential("user", "password"); MailMessage msg = new MailMessage("sendaddr@gm..

Programming/C#

Comparison of built-in collections

출처: Pluralsight Making .Net Application Faster 참고 : HashSet Hashset : 중복된 데이터 없이 해싱에 의해 데이터를 저장하는 자료구조. 기본적으로 데이터의 저장순서는 알 수 없다. (Hashset은 Hashing을 이용해서 데이터만 저장함.)​ ​ 해싱(Hashing) : 저장을 위해서 주소를 결정하는 방법. List는 데이터를 순서대로 저장 (배열, ArrayList, Stack, Queue, Deque, (LinkedList만 빼고) 해싱은 %4로 나눈 것을 이용한 나머지로 정보를 저장함. (결과를 담을 공간이 필요) 해싱을 쓰는 이유 : 현재 이 방식이 가장 검색이 빠름. (모든 데이터의 접근속도가 일정. 나머지 구하는 계산 + 주소찾기. 메모리의 ..

Programming/C#

C# Tip and Traps 3.

1. Parsing Numeric types using NumberStyles 각 기본 자료형에는 Parsing 함수를 갖고 있다. 문자열을 입력받고 이를 맞는 형식의 숫자로 변환하는 함수이다. Pasring 함수에 NumberStyle 옵션을 이용하면 더욱 쉽게 pasring을 수행할 수 있다. NumberSytle의 옵션들이다. 아래의 PremadeComposites 예문은 여러 NumberStyle option을 중첩하여 하나로 만들어진 옵션을 이용한 Pasring 예문이다. 또한, Custom Numberformat 을 설정하여 Parsing 을 수행할 수도 있다.

Programming/C#

C# Tip and Traps 2

1. Changing Thread Culture [TestMethod] public void Example() { const string turkeyCultureString = "tr-TR"; const string australiaCultureString = "en-AU"; const double someNumber = 23.45; Debug.WriteLine("Setting English language - Australia country/region" ); var australiaCultureInfo = CultureInfo.GetCultureInfo(australiaCultureString); Thread.CurrentThread.CurrentCulture = australiaCultureInfo..

Programming/C#

C# Tip and Traps 1.

1. DebuggerDisplay Attribute : Debugging 시에 데이터의 속성을 사용자가 원하는 형태로 출력할 수 있는 속성을 지정한다. 예) [DebuggerDisplay("This person is called {Name} and is {AgeInYears} years old")] class PersonWithDebuggerDisplay { [DebuggerDisplay("{AgeInYears} years old")] public int AgeInYears { get; set; } public string Name { get; set; } } 사용 범위 : Classes , Structs, Delegates, Enums, Fields, Properties, Assemblies 2. De..

Programming/C#

Net Faster 1. Value Type

Value Type 을 사용함에 있어서 .Net Framework를 빠르게 만드는 Tip을 설명한다. 우선 Value Type 과 Reference Type은 메모리 구조적으로 차이가 있다. 아래에서 보면 Reference Type은 두개의 헤더 필드를 갖는다. Object header Word는 32bit에서는 4byte, 64bit에서는 8byte의 길이를 갖는다. 이러한 차이로 객체를 수없이 많이 사용할 때에는 메모리의 차이가 극심해 진다. struct/class Point2 { int X, int Y } 만약 위의 Point2와 같은 객체를 1만개 생성할 때에는 Reference type의 경우는 32만 byte를 갖게 되며 Value Type의 경우에는 8만 byte를 갖는다. 두 type의 메..

Programming/C#

Linq Query 실행 타이밍

다음과 같은 foreach 구문이 있다. foreach (var c in customerList) { if (c.CustomerId == customerId) { foundCustomer = c; break; } } 위의 foreach 구문과 같은 내용을 Linq를 이용하여 표현하면 아래와 같다. var query = from c in customerList where c.CustomerId == customerId select c; foundCustomer = query.First(); 두 구문을 비교해 보면, foreach의 경우는 loop를 돌면서 customerId와 같으면 loop를 빠져 나올수 있다. 하지만, 직관적인 관점에서 봤을 때 linq 구문에서는 customerList의 모든 값에 대..

RichardBang
'Programming/C#' 카테고리의 글 목록 (3 Page)