我无法在 C# 11 中传递对结构中值的引用。我该怎么做?
未处理的异常。System.NullReferenceException:未将对象引用设置为对象的实例。在路径\Program.cs 中的 CustomRef..ctor(Double& number) 处:第 17 行 在路径\Program.cs 中的 Program.$(String[] args) 处:第 4 行
using System.Runtime.CompilerServices;
var x = 1.1;
var myTuple = new CustomRef(ref x);
x = 2.2;
Console.WriteLine(x); // Outputs 2.2
Console.WriteLine(myTuple.GetNumber()); // Outputs 2.2
public ref struct CustomRef
{
private readonly ref double _number;
public CustomRef(ref double number)
{
_number = number;
}
public double GetNumber()
{
if (Unsafe.IsNullRef(ref _number))
{
throw new InvalidOperationException("The number ref field is not initialized.");
}
return _number; …Run Code Online (Sandbox Code Playgroud) 我刚刚了解到我可以将 VS 2019 与 C++ 20 一起使用,并且我正在尝试使用它。我正在尝试使以下功能使用std::span,因为那样做data_size并且key_size将是多余的。
一切都好,除了*data和data++。它应该是什么?
int rc4(rc4_context* context, const std::uint8_t* data, const std::size_t data_size, const std::uint8_t* key, const std::size_t key_size, std::uint8_t* output)
{
std::uint32_t i, j;
// Check parameters
if (!context || !key)
return ERROR_INVALID_PARAMETER;
// Clear context
context->i = 0;
context->j = 0;
// Initialize the S array with identity permutation
for (i = 0; i < 256; i++)
{
context->s[i] = static_cast<std::uint8_t>(i);
}
// S …Run Code Online (Sandbox Code Playgroud) 我想在 C/C++ 项目中加载 C# 程序集,因为本机加载器对我来说似乎很酷,但是mscorlib.tlh. 首先,我正在关注代码项目示例(第一个片段)。我创建了一个空的 C++ 项目,起初它似乎没有找到,mscorlib.tlb但是在更改 SDK 版本/平台工具集后,它找到了但有一些错误。
当前设置:
Windows SDK 版本:10.0.17763.0
平台工具集:Visual Studio 2017 (v141)
错误:
1>main.cpp
1>c:\users\admin\desktop\netloader\netloader\debug\mscorlib.tlh(12974): error C2143: syntax error: missing ')' before '||'
1>c:\users\admin\desktop\netloader\netloader\debug\mscorlib.tlh(12974): error C2143: syntax error: missing ';' before '||'
1>c:\users\admin\desktop\netloader\netloader\debug\mscorlib.tlh(12974): error C2059: syntax error: '||'
1>c:\users\admin\desktop\netloader\netloader\debug\mscorlib.tlh(12974): error C2059: syntax error: ')'
1>c:\users\admin\desktop\netloader\netloader\debug\mscorlib.tlh(12974): error C2238: unexpected token(s) preceding ';'
1>c:\users\admin\desktop\netloader\netloader\debug\mscorlib.tlh(12977): error C2143: syntax error: missing ')' before '||'
1>c:\users\admin\desktop\netloader\netloader\debug\mscorlib.tlh(12977): error C2143: syntax error: missing ';' before …Run Code Online (Sandbox Code Playgroud) 此查询使用大量 CPU,执行时间约为 30 秒。我可以做什么来改善它?
它使用 s 的原因join是因为没有适当的关系。我刚刚添加了一些并开始替换所有存储库,因为这是使用 EF Core 并且 EF Core 已经基于存储库和工作单元。
var employeeLocations = await _dbContext.Set<LocationEmployee>()
.Include(x => x.Employee)
.Where(x => x.Employee.Email == _userEmail && x.IsActive && (x.CanBuy || x.CanSell))
.ToListAsync(cancellationToken);
Run Code Online (Sandbox Code Playgroud)
还有什么?有想法吗?
我有一种感觉,这Union就是导致缓慢的原因。
public class GetAllReviewAndReleaseQuery : IRequest<ListDto<ReviewAndReleaseItemDto>>
{
public ReviewAndReleaseFilterDto Filter { get; set; }
}
public sealed class GetAllReviewAndReleaseQueryHandler : IRequestHandler<GetAllReviewAndReleaseQuery, ListDto<ReviewAndReleaseItemDto>>
{
readonly MarketTransactionRepository _marketTransaction;
readonly ProductRepository _productRepository;
readonly CommodityRepository _commodityRepository;
readonly ILogger<GetAllReviewAndReleaseQueryHandler> _logger;
readonly OfferMonitoringRepository _offerMonitoringRepository;
readonly OfferRepository _offerRepository; …Run Code Online (Sandbox Code Playgroud) c# indexing sql-server-profiler entity-framework-core azure-sql-database