在学习C#时,我想到了这个问题.void和之间有什么区别var?以下是我想分享的两个例子:
void * voidInt = (void *) 7;
void * voidChar = (void *) 'F';
void * voidCharArray = (void *) "AbcString";
Run Code Online (Sandbox Code Playgroud)
这是一个例子var:
var varInt = 7;
var varChar = 'F';
var varCharArray = "AbcString";
Run Code Online (Sandbox Code Playgroud)
void一个匿名的数据类型? var和之间的主要区别是void什么?有人能帮助我清除这种情况吗?
如果我有一个同步方法"GetStrings()":
private static Task<string[]> GetStrings(IEnumerable<int> ids)
{
var tasks = ids.Distinct().Select(GetString);
return Task.WhenAll(tasks);
}
private static async Task<string> GetString(int stringId)
{
await Task.Delay(15000);
return "hello" + stringId;
}
Run Code Online (Sandbox Code Playgroud)
(它本身称为异步方法"GetString()")
我从异步方法中调用这个同步 "GetStrings()" 方法:
public static async Task Main()
{
var ids = new List<int> { 1, 2, 3 };
await GetStrings(ids);
Console.WriteLine("all done");
Console.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)
什么是行为差异,if GetStrings()实际上是异步的?(并进行了等待Task.WhenAll)
它会直接阻止Task.WhenAll阻塞线程吗?我找到了一些看起来像这样的生产代码,所以我把这个小例子放在一起试着去了解发生了什么.但是很难确定差异.
我想知道是否有人可以帮助我理解ISO 8583 Field 22POS输入模式之间的区别.我已经知道了:
52 指ICC卡80 在后退的情况下但我想知道的是两者之间的区别
22 (磁条)90谁可以帮我这个事?
我在 Visual Studio 2015 中为 C 锐利项目工作。运行项目时,我在浏览器中收到以下错误
无法加载文件或程序集“Microsoft.Diagnostics.Tracing.EventSource,Version=1.1.24.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a”或其依赖项之一。该系统找不到指定的文件。
任何人都可以为我提供解决方案
当我需要执行以下操作时,我试图找出 LINQ 的正确约定是什么
"No items"我想这样做的方式就像
if (items.Any())
{
foreach (string item in items)
{
Console.WriteLine(item);
}
}
else
{
Console.WriteLine("No items");
}
Run Code Online (Sandbox Code Playgroud)
然而,这在技术上违反了多重枚举原则。一种不违反这一点的方法是
bool any = false;
foreach (string item in items)
{
any = true;
Console.WriteLine(item);
}
if (!any)
{
Console.WriteLine("No items");
}
Run Code Online (Sandbox Code Playgroud)
但显然,这不太优雅。
我昨天刚刚了解 Fluent Validation,我认为它非常酷。我已经尝试过并且有效。但我的应用程序目前有多个模型,我必须承认为每个模型编写验证器很有压力。是否有可能用泛型编写它并找到一种方法来验证每个模型?
这就是我的验证器目前的编写方式。但我不知道如何用泛型编写它。
EmployeeValidator.cs
public class EmployeeValidator : AbstractValidator<EmployeeViewModel>
{
private readonly ValidationEntitySettingServices _validationEntitySettingService;
public EmployeeValidator(ValidationEntitySettingServices validationEntitySettingService)
{
_validationEntitySettingService = validationEntitySettingService;
RuleFor(x => x.LastName).NotEmpty().When(x => IsPropertyRequired(x.LastName)).WithMessage("Last Name is a required field!");
RuleFor(x => x.FirstName).NotEmpty().When(x => IsPropertyRequired(x.FirstName)).WithMessage("First Name is a required field!");
RuleFor(x => x.MiddleName).NotEmpty().When(x => IsPropertyRequired(x.MiddleName)).WithMessage("Middle Name is a required field!");
}
public bool IsPropertyRequired(string propertyName)
{
var empValidationSetting = _validationEntitySettingService.GetIncluding("Employee");
if (empValidationSetting != null)
{
return empValidationSetting.ValidationEntityProperties.Any(p => p.PropertyName.Equals(propertyName) && p.IsRequired);
}
else
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
提前致谢。
我从客户端调用SOAP API时,随机接收(并非总是)"接收到HTTP响应时出错".它不会每次都发生.我的应用程序本身是一个WCF服务.
客户端配置:
<binding name="AbcBinding"
sendTimeout="00:02:45"
closeTimeout="00:02:45"
openTimeout="00:02:45"
receiveTimeout="00:10:00"
bypassProxyOnLocal="false"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="Transport" >
<transport clientCredentialType="Basic" />
</security>
</binding>
<client>
<endpoint binding="basicHttpBinding" bindingConfiguration="AbcBinding"
contract="AbcContract" name="AbcBinding" />
</client>
Run Code Online (Sandbox Code Playgroud)
码:
var configFactory = new ConfigurationChannelFactory<AbcContract>("AbcBinding"), ConfigFile, "localhost:9198/AbcCall");
#region Basic http authentication
if (configFactory.Credentials != null)
{
var defaultCredentials = configFactory.Endpoint.Behaviors.Find<ClientCredentials>();
configFactory.Endpoint.Behaviors.Remove(defaultCredentials);
var loginCredentials = new ClientCredentials();
loginCredentials.UserName.UserName = "UserName";
loginCredentials.UserName.Password = "Password";
configFactory.Endpoint.Behaviors.Add(loginCredentials);
}
Run Code Online (Sandbox Code Playgroud)
编辑
在本地环境中,它可以正常工作,具有以下配置:useDefaultWebProxy="false" proxyAddress="http://127.0.0.1:8888"
但在部署服务器上,我遇到以上配置错误: …
当我使用代码
Properties.Settings.Default.Save();
Run Code Online (Sandbox Code Playgroud)
为了保存我的设置,它将文件写入该路径
%USERPROFILE%\AppData\Local\MyAppName\MyAppName.exe_Url_SomeWiredCode\TheAppVersionNumber\user.config
Run Code Online (Sandbox Code Playgroud)
喜欢
"C:\Users\Username\AppData\Local\MyApp\MyApp.exe_Url_claumreyuxtgqul2vuc3couyu5tso2n0\1.0.0.0\user.config"
Run Code Online (Sandbox Code Playgroud)
如何获取“应用程序版本”文件夹的路径,以便我可以向其中写入其他内容?
我正在使用 .Net Framework 4.6.2 和 Visual Studio 2017。
当我尝试访问Authorize Attribute下的方法时,我正在尝试写入日志。基本上,我想记录一个人是否使用了无效的令牌或过期的令牌。我正在对JWT使用基本身份验证
services.AddAuthentication(o =>
{
o.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
o.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(cfg =>
{
cfg.RequireHttpsMetadata = false;
cfg.SaveToken = true;
cfg.TokenValidationParameters = new TokenValidationParameters()
{
ValidAudience = jwtAudience,
ValidIssuer = jwtIssuer,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSecurityKey))
};
});
Run Code Online (Sandbox Code Playgroud)
有什么方法可以向授权检查中添加一段代码,以记录授权尝试是否有效以及为何无效?
c# ×8
.net ×2
.net-4.5.2 ×1
.net-core ×1
algorithm ×1
asp.net-core ×1
asynchronous ×1
c++ ×1
generics ×1
iso8583 ×1
jwt ×1
linq ×1
rider ×1
wcf ×1
wcf-client ×1
wpf ×1