Digging up a series of things we don't use in C # (4)--gethashcode,expandoobject

Source: Internet
Author: User

One: GetHashCode

The explanation that you can see from MSDN is that it is used as a hash function for a particular type, that is, an instance of any object will have a int32 type of hashcode, and stored in the FCL

Hashcollection, the nonsense does not say, look at an example:

As you can see, the hashcode of the two class instances is different, stating that they are not the same reference, and there are different hashcode, using this feature, we are not

Can you generate some random numbers?

1: Generated with random in the For loop.

1         Static voidMain (string[] args)2         {3             varList =Newlist<int>();4 5              for(inti =0; I <byte. MaxValue; i++)6             {7List. ADD (NewRandom (). Next (0,byte. MaxValue));8             }9 TenList. ForEach ((i) = = One             { A Console.WriteLine (i); -             }); -  the Console.read (); -}

We know that random is pseudo-random, so there will be a series of repetition of numbers, so what do I really want to do with random numbers? You can try it with hashcode.

Hashcode in the 2:for cycle

1         Static voidMain (string[] args)2         {3             varList =Newlist<int>();4 5              for(inti =0; I <byte. MaxValue; i++)6             {7List. ADD (NewRandom (). GetHashCode ());8             }9 TenList. ForEach ((i) = = One             { A Console.WriteLine (i); -             }); -  the Console.read (); -}

However, we see that we continue to push the garbage to the host, so there is a certain performance cost to the GC.

Two: ExpandoObject

We know that Php,asp,js is an explanatory language, eliminating the hassle of compiling, I did six months of PHP last year, and then return to C #, and then the C # compiler is particularly uncomfortable

, sometimes a solution of more than 100 DLLs, compilation will take more than 10 minutes, the weekly release date will be released through automated tools to the production environment, but in the production environment before the various ring

Environment, all need to recompile, resulting in a lot of time spent on the compilation, but after c#4.0, we can use the dynamic characteristics of C # as JS to write.

For example, the ExpandoObject class here, we can use late binding to ExpandoObject dynamically append some properties and methods, very interesting. But it's important to note that

Once the dynamic is opened, the compiler will not recognize the code, waiting for the CLR inside the JIT to run it, so as to achieve the compiler-free function.

1         Static voidMain (string[] args)2         {3Dynamic obj =NewSystem.Dynamic.ExpandoObject ();4             5Obj. Name ="HxC";6 7Obj. Age = -;8 9Obj. Call =NewAction (() = {Console.WriteLine ("Call me!!!"); });Ten  One obj. Call (); A  - Console.read (); -}

Copyright NOTICE: This article for Bo Master http://www.zuiniusn.com original article, without Bo Master permission not reproduced.

Digging up a series of things we don't use in C # (4)--gethashcode,expandoobject

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.