小编ger*_*per的帖子

如何按元素列表分组?

我一次又一次地遇到这个问题:如何通过包含其他对象列表来对对象列表进行分组?

我有一个类型对象的列表,A每个对象都有一个属性(让我们称之为ListProp),这也是一个列表.ListProp有类型的元素B.有多个类型的元素A具有相同的B-objects ListProp,但ListProp属性引用因元素而异.如何A以最快的方式对这些对象进行分组,其中B-objects ListProp是相同的?

示例代码:

class Program
{
    static void Main(string[] args)
    {
        var exampleList = new List<A>
        {
            // Should be in first group
            new A { ListProp = new List<B>
            {
                new B { Prop = new C { Number = 0 }},
                new B { Prop = new C { Number = 1 }}
            }},
            // Should …
Run Code Online (Sandbox Code Playgroud)

.net c# linq group-by

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

是否可以在C#/ LINQ中扩展查询关键字?

是否可以使用自己的定义扩展Linq的查询关键字(如:select,where等)?

Codeexample使其更清晰:

System.Collections.Generic.List<string> aList = 
    new System.Collections.Generic.List<string> { "aa", "ab", "ba", "bb" };

// instead of
string firstString = (from item in aList
                      where item.StartsWith("a")
                      select item).First();

// would be nice
string firstString = from item in aList
                     where item.StartsWith("a")
                     selectFirst item;

// or something else
from item in aList
where item.StartsWith("a")
WriteLineToConsole item;
Run Code Online (Sandbox Code Playgroud)

我认为这不可能,但仍希望;)

c# linq select

7
推荐指数
2
解决办法
909
查看次数

C# 的多个异常的 XML 文档

我实际上正在寻找指导方针,如何在 C#-DLL 内的公共方法中记录多个异常。

例子:

/// <summary>
/// This method does something
/// </summary>
/// <param name="p_Parameter1">First parameter</param>
/// <param name="p_Parameter2">Second parameter</param>
/// <param name="p_Number">A number</param>
/// <exception cref="ArgumentNullException">
/// Thrown if p_Parameter1 is null</exception>
/// <exception cref="ArgumentNullException">
/// Thrown if p_Parameter2 is null</exception>
/// <exception cref="ArgumentNullException">
/// Thrown if any element of p_Parameter2 is null</exception>
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown if p_Number is below or equal 0</exception>
/// <returns>A object</returns>
Run Code Online (Sandbox Code Playgroud)
public static object DoSomething(
    object p_Parameter1, IList<object> p_Parameter2, 
    object p_Parameter3, …
Run Code Online (Sandbox Code Playgroud)

c# exception visual-studio-2010 xml-documentation

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