小编Rus*_*sel的帖子

使用扩展方法的集合随机化

可能重复:
C#:使用Random和OrderBy是一个很好的shuffle算法吗?

我想创建一个扩展方法,该方法应该对集合中的项进行随机播放.

我能改进以下内容吗?

public static IList<T> RandomList<T>(this IList<T> source)
{
   if (source.Count <= 0) throw new ArgumentException("No Item to Randomize");  

            for (int i =source.Count-1 ; i>0; i--)
            {
                int RandomIndex = Rnd.Next(i + 1);
                T temp = source[i];
                source[i] = source[RandomIndex];
                source[RandomIndex] = temp;
            }

            return source;
 }
Run Code Online (Sandbox Code Playgroud)

c# extension-methods

4
推荐指数
1
解决办法
981
查看次数

C#匿名类型

当我说匿名类型声明

var someType = new {Name ="Jon Skeet",年龄= 10};

然而关键字

var is  implicitly typed
Run Code Online (Sandbox Code Playgroud)

但是当我打印

Response.Write(someType.GetType().Name);
Run Code Online (Sandbox Code Playgroud)

它产生<>f__AnonymousType02 .这个符号<>与什么有关?

c# anonymous-types

3
推荐指数
1
解决办法
832
查看次数

C#序列选择

只是我想找到任何的intCollCustomerData的长度为个位数的,并选择customerData.

List<CustomerData> cdata = new List<CustomerData>();

cdata.Add(
           new CustomerData { Key = 1, Name = "Marc",
                              intColl = new List<int>() { 1, 2, 3 }
                             }
         );


cdata.Add(
           new CustomerData { Key = 2, Name = "Eric",
                             intColl = new List<int>() { 11, 12, 13 }
                            }
         );


cdata.Add(
           new CustomerData { Key = 3, Name = "Peter", 
                              intColl = new List<int>() { 111, 112, 113 }
                             }
         );  


cdata.Add(
            new CustomerData { Key = 4, …
Run Code Online (Sandbox Code Playgroud)

c# linq

1
推荐指数
1
解决办法
139
查看次数

标签 统计

c# ×3

anonymous-types ×1

extension-methods ×1

linq ×1