Add sorting functions for list to handle parallel rankings (previous)

Source: Internet
Author: User
Tags foreach range tostring

Today. Do a ranking display function. Need to deal with the situation in parallel. First, it's the rank function of SQL SERVER2005.

I later wondered if it would be possible to implement an extension method for list<t> to achieve a parallel ranking.

Think about it can be achieved. Have this idea to come true.

My idea is that when List<t> calls the Rank method, the T type has an extra attribute to get the rank.

But how to dynamically add properties to the T type ... I think of the dynamic creation of a type.

. NET can dynamically create a type ... .

There are 2 general ways (I only know 2 total ...). I also thought of a dynamic construct lambda using new{} I don't know if I can. I think it should be OK. Never tried (just think))

Mode 1: Use the class under the System.Reflection.Emit namespace. (both directly or indirectly manipulate the IL code)

Mode 2: Use Microsoft.csharp; System.CodeDom.Compiler; This 2-namespace class can be implemented relatively simple.

Let's start by looking at how to create a type dynamically.

Dynamic Create type first name is dynamic.

This method is very simple. is to get 26 uppercase and lowercase letters using ASCII code.

/// <summary>
        /// 动态创建一个英文名称
        /// </summary>
        /// <param name="number">长度</param>
        /// <returns></returns>
        public static string CreateEnglish(int number)
        {
            Random random = new Random(DateTime.Now.Millisecond);
            List<string> en = new List<string>();
            Enumerable.Range(97, 26).ToList<int>().ForEach(t => en.Add(((char)t).ToString()));
            Enumerable.Range(65, 26).ToList<int>().ForEach(t => en.Add(((char)t).ToString()));
            string reuslt = string.Empty;
            for (int i = 0; i < number; i++)
            {
                reuslt += en[random.Next(en.Count)];
            }
            return reuslt;
        }

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.