小编Jak*_*net的帖子

GroupBy on complex object(例如List <T>)

使用GroupBy()和Count() > 1我试图在列表中查找我的类的重复实例.

这个类看起来像这样:

public class SampleObject
{
    public string Id;
    public IEnumerable<string> Events;
}
Run Code Online (Sandbox Code Playgroud)

这就是我实例化和分组列表的方式:

public class Program
{
    private static void Main(string[] args)
    {
        var items = new List<SampleObject>()
        {
            new SampleObject() { Id = "Id", Events = new List<string>() { "ExampleEvent" } },
            new SampleObject() { Id = "Id", Events = new List<string>() { "ExampleEvent" } }
        };

        var duplicates = items.GroupBy(x => new { Token = x.Id, x.Events })
                         .Where(g => g.Count() …
Run Code Online (Sandbox Code Playgroud)

c# linq comparison grouping

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

错误从NUnit 2升级到NUnit 3时,"异步测试方法必须具有非void返回类型"

我必须重构从NUNIT 2到NUNIT 3的单元测试,并且以下语法抛出错误:

var expectedResponseMessage = new HttpResponseMessage();
Func<Task<HttpResponseMessage>> continuation = 
   () => Task.Factory.StartNew(() => expectedResponseMessage);
Run Code Online (Sandbox Code Playgroud)

错误:

异步测试方法必须具有非void返回类型

我怎么能改写这个?我尝试了很多语法,但没有运气.谢谢.

c# async-await nunit-3.0

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

NUNIT 3 和 ExpectedException

我想从 NUNIT 2.x 升级到 3.x 但我有类似的测试

[TestCase("12345", ExpectedResult = "SUCCESS")]
[TestCase("invalidkey", ExpectedException = typeof(ArgumentException))]
[TestCase(null, ExpectedException = typeof(ArgumentNullException))]
public string ReturnsStatus(string filePath)
{
    // Arrange

    // Act
    Tuple<string, string> result = service.Create(filePath);

    // Assert
    return result.Item1;
}
Run Code Online (Sandbox Code Playgroud)

如何重写这种测试?NUNIT 3.x 没有 ExpectedException,这是我重构的原因。我不想分成 3 个测试。谢谢。

c# nunit

7
推荐指数
3
解决办法
4998
查看次数

HttpUtility不解码"&#134047;"

与其他所有字符一起HttpUtility运行良好,但使用此编码值,&#134047;它只是不想解码.

解码应该是.

附图:http://screencast.com/t/r3TxPHrYr5

c# decode

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

为什么数组需要在定义时设置维度?

我只是想知道,为什么我们不能只定义这样的东西:

int[] arr = new int[];
arr[0] = 1;
Run Code Online (Sandbox Code Playgroud)

像列表一样,自动调整大小.我想知道的是为什么这是不可能的,我们需要按以下方式设置每次大小:

int[] arr = new int[1];
arr[0] = 1;
Run Code Online (Sandbox Code Playgroud)

c# arrays

4
推荐指数
2
解决办法
214
查看次数

如何将时区添加到 DateTime.UtcNow?

我有一个从客户那里收到的时区,我用它来设置到期日期时间,以便它相当于客户时区中的“月末”的 UTC。

我试过这个:

var current = timezone.ToUniversalTime(DateTime.UtcNow);
Run Code Online (Sandbox Code Playgroud)

但无法工作。有人可以帮我吗?

c# datetime

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

有没有更好的方法来编写这个字符串插值?

我必须编写一段漂亮的代码,但我对以下语法不满意.

有没有更好的方法来编写这个字符串插值?

var details = $"{((currentProfile.FirstName != newProfile.FirstName) ? $"{Environment.NewLine}First Name : {newProfile.FirstName}" : string.Empty)}" +
    $"{((currentProfile.LastName != newProfile.LastName) ? $"{Environment.NewLine}Last Name : {newProfile.LastName}" : string.Empty)}" +
    $"{((currentProfile.MiddleName != newProfile.MiddleName) ? $"{Environment.NewLine}Middle Name : {newProfile.MiddleName}" : string.Empty)}" +
    $"{((currentProfile.Suffix != newProfile.Suffix) ? $"{Environment.NewLine}Suffix : {newProfile.Suffix}" : string.Empty)}" +
    $"{((currentProfile.AddressLine1 != newProfile.AddressLine1) ? $"{Environment.NewLine}Address Line 1 : {newProfile.AddressLine1}" : string.Empty)}" +
    $"{((currentProfile.AddressLine2 != newProfile.AddressLine2) ? $"{Environment.NewLine}Address Line 2 : {newProfile.AddressLine2}" : string.Empty)}" +
    $"{((currentProfile.City != newProfile.City) ? $"{Environment.NewLine}City : {newProfile.City}" : …
Run Code Online (Sandbox Code Playgroud)

c# string-interpolation

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

SQL查询 - 仅在另一个条件下在WHERE中添加条件

我想在where子句中做这样的事情

WHERE ( i.accountid = @accountid 
      AND CASE WHEN @IsTest IS NOT NULL THEN b.IsTest = @IsTest ELSE 1 = 1
Run Code Online (Sandbox Code Playgroud)

但是这个解决方案不起作用.对此有什么解决方案吗?基本上我想根据@IsTest价值添加验证.

sql where-clause

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