小编Mr *_*nce的帖子

ASP.NET Core JWT - HmacSha512 和 HmacSha512Signature 算法有什么区别?

课堂上有这两个类似的选项SecurityAlgorithms。应该使用哪一个来签署 JWT 令牌?有什么区别吗?

c# jwt asp.net-core

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

“Type”无法满足参数“TParam”的“new()”约束,因为“Type”具有必需的成员

我有这个类结构(简化):

public class InducingMedium
{
   public required string File { get; set; }
}

public class InducingVideo : InducingMedium {}
public class InducingAudio : InducingMedium {}
Run Code Online (Sandbox Code Playgroud)

现在,我想一般实例化特定类型的实例:

public abstract class BaseInducingTests<TMedium>
    where TMedium : InducingMedium, new()
{
   protected async Task<IEnumerable<TMedium>> CreateInducingMedia(IEnumerable<string> files)
   {
      return files.Select(file =>
      {
          // Do some processing...

          return new TMedium
          {
              File = file,
          };
      });
   }
}

public class InducingVideosTests : BaseInducingTests<InducingVideo>
{
}
Run Code Online (Sandbox Code Playgroud)

但在派生类中我收到错误:

'Namespace.InducingVideo' cannot satisfy the 'new()' constraint 
on parameter 'TMedium' in …
Run Code Online (Sandbox Code Playgroud)

c# generics .net-7.0

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

“Where”中新对象的Linq查询性能

这之间是否存在性能差异:

var listOfFoo = bar.Where(x => x.Id == new Guid("sth")).toList();

Run Code Online (Sandbox Code Playgroud)

和这个:

var guid = new Guid("sth");
var listOfFoo = bar.Where(x => x.Id == guid).toList();
Run Code Online (Sandbox Code Playgroud)

?

可能不是什么时候bar是某种动态集(然后查询转换为 SQL)。
但如果它是一个简单的枚举呢?

c# linq performance lambda compiler-optimization

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

异步方法彼此等待

我正在尝试运行异步程序.
主要有:

using System;
using System.Threading.Tasks;

namespace Test
{
class Program
{
    static void Main(string[] args)
    {
        RunTestsAsync().Wait();
    }

    private async static Task RunTestsAsync()
    {
        var a = new SlowString("ab", true);
        var b = new SlowString("c", true);

        var result1 = a.Equal(b);
        var result2 = b.Last(b);
        var result3 = b.GreaterThen(a);

        result1.Wait();
        result2.Wait();
        result3.Wait();

        Console.WriteLine();
        Console.WriteLine("Results: {0},   {1},   {2}", result1.Result, result2.Result, result3.Result);
        Console.WriteLine();
    }
}
}
Run Code Online (Sandbox Code Playgroud)

这是第二个文件:

using System;
using System.Threading.Tasks;

namespace Test
{
class SlowString
{
    private readonly string str;
    private …
Run Code Online (Sandbox Code Playgroud)

.net c# async-await

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

在c ++中包含标题

我有这样的事情:

//main.cpp
#include <add.h>

cin >> a;
cin >> b;
cout << add(a,b);


//add.h
#ifndef add_h
#define add_h

int add(int a, int b);

#endif 


//add.cpp
int add(int a, int b){
    return a+b;
}
Run Code Online (Sandbox Code Playgroud)

我是否应该在add.cpp中包含add.h,或者我只能在main.cpp中包含它?
我问,因为我在某个地方看到了,我很好奇哪条路更好.

c++ header include

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