我最近看到了以下代码:
public class Person
{
//line 1
public string FirstName { get; }
//line 2
public string LastName { get; } = null!;
//assign null is possible
public string? MiddleName {get; } = null;
public Person(string firstName, string lastName, string middleName)
{
FirstName = firstName;
LastName = lastName;
MiddleName = middleName;
}
public Person(string firstName, string lastName)
{
FirstName = firstName;
LastName = lastName;
MiddleName = null;
}
}
Run Code Online (Sandbox Code Playgroud)
基本上我试着深入研究新的c#8功能.其中之一是NullableReferenceTypes.实际上已经有很多关于它的文章和信息.例如,这篇文章非常好.但是我找不到关于这个新陈述的任何信息null!
有人可以向我提供解释吗?为什么我需要使用它?又什么区别line1和line2?
我需要在CSS中更改禁用的输入元素的样式.
<input type="text" class="details-dialog" disabled="disabled" />
Run Code Online (Sandbox Code Playgroud)
我如何为Internet Explorer执行此操作?
我有Visual Studio 2012 Express for Web.我的步骤 - 创建一个新的ASP .NET MVC 4应用程序 - 选择基本模板-go到Package Manager Console -try来安装WebActivator
PM> Install-Package WebActivator
Run Code Online (Sandbox Code Playgroud)
我得到以下错误

我如何解决这个问题并安装WebActivator包?
我很困惑是否可以sdk-style .net framework在 Visual Studio 中创建一个项目(更具体地说,我使用最新的 VS2019)。还是仍然需要手动操作?
<Project Sdk="Microsoft.NET.Sdk">
Run Code Online (Sandbox Code Playgroud)
我有兴趣创建一个新项目,而不是将现有项目从旧.csproj文件样式迁移到新的.csproj sdk-style. 我已经.csproj手动编辑过很多次文件了,但是超级不方便。
我正在使用Telegram Bot API向用户发送即时消息.我已经安装了nuget包.电报开发人员推荐这个软件包.
我创建了一个电报机器人,并使用代码成功访问了它.当我向机器人发送消息时,机器人会获得有关发送者的一些信息.
我需要用户的电话号码在我们的系统中识别它们并将信息发回给他们.
我的问题是我可以获得用户电话号码telegramUserId吗?
我这样做是为了方便用户.如果我能得到用户电话号码,我不应该向用户索要.
现在我的命令是这样的:
debt 9811201243
Run Code Online (Sandbox Code Playgroud)
我想要
debt
Run Code Online (Sandbox Code Playgroud) <input class="jProblemClass" id="Checkbox{%= ID %}" type="checkbox" onchange="problemPicker.onChangeProblemCheckBox('{%=ID %}');"/>
Run Code Online (Sandbox Code Playgroud)
首先检查或取消选中后没有任何反应.Afetr第二次点击,调用我的功能problemPicker.onChangeProblemCheckBox,但我先得到ID检查.为什么?可以帮助我吗?
onChangeProblemCheckBox: function(id) {
if ($('#CheckBox' + id).attr("checked") == true) {
problemPicker.addToCheckProblems(id);
var checkboxes = $('.jProblemClass:checked');
if ((checkboxes.length > general.limit) && (general.limit != 0)) {
alert('The limit of ' + general.limit + ' problems exceeded. Please deselect ' + (checkboxes.length - general.limit).toString() + '.');
}
} else {
problemPicker.delFromCheckProblems(id);
}
},
Run Code Online (Sandbox Code Playgroud) 我玩新c# 8.0 NullableReferenceTypes功能已有一段时间了。我对通过更改.csproj文件来启用此功能有些困惑。
我的意思是,要启用此功能,您必须在.csproj文件中放入以下几行:
<PropertyGroup>
<LangVersion>8.0</LangVersion>
<NullableContextOptions>enable</NullableContextOptions>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
但我也找到了另一种方法:
<PropertyGroup>
<LangVersion>8.0</LangVersion>
<NullableReferenceTypes>true</NullableReferenceTypes>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
所以几乎一样,但无论如何。NullableContextOptions和之间有什么区别NullableReferenceTypes?
目前,我正在使用这个c# 8.0名为range的新功能。
到目前为止,我有一个问题。我可以range从头到尾创建一个吗?
可以说我有一个array,我想通过range以下方式将其打印出来:
static void Test()
{
int[] array = new int[10];
for (int i = 0; i < 10; i++) array[i] = i;
Range range = ^1..0;
foreach (int v in array[range]) WriteLine(v);
}
Run Code Online (Sandbox Code Playgroud)
但这给了我一个运行时错误- System.OverflowException: 'Arithmetic operation resulted in an overflow.'那么我是正确的,只允许一个方向(从开始到结束)ranges吗?
public class SharedCacheData : ISharedCacheData
{
private readonly ISharedPetsService mPetsService;
private static ISharedEmployeeService mSharedEmployeeService;
public SharedCacheData(ISharedPetsService petsService, ISharedEmployeeService employeeService)
{
mPetsService = petsService;
mSharedEmployeeService = employeeService;
}
public static string GetUserFullName(string key)
{
Hashtable value = HttpContext.Current.Application[USERFULLNAME_KEY] as Hashtable;
if (value == null)
{
value = new Hashtable();
HttpContext.Current.Application[USERFULLNAME_KEY] = value;
}
if (value.ContainsKey(key))
return value[key] as string;
string name = mSharedEmployeeService.FindOneUser(key);
value[key] = name;
return name;
}
Run Code Online (Sandbox Code Playgroud)
是否在构造函数中初始化静态字段mSharedEmployeeService(service)?
它是用一个好主意,nameof在expressions提取属性的名称?
//method with expression
protected void RaisePropertyChanged<T>(Expression<Func<T>> propertyExpression, bool isValid, [param: Localizable(true)] string validationError)
{
string propertyName = PropertySupport.ExtractPropertyName(propertyExpression);
RaisePropertyChanged(propertyName, isValid, validationError);
}
//the same logic without expression
protected void RaisePropertyChanged(string propertyName, [param: Localizable(true)] string validationError)
{
RaisePropertyChanged(propertyName, validationError == null, validationError);
}
Run Code Online (Sandbox Code Playgroud)
但呼唤是不同的
public string Url
{
set
{
//with nameof
RaisePropertyChanged(nameof(Url), this.GetValidationError());
//with expression
RaisePropertyChanged(() => Url, this.GetValidationError());
}
}
Run Code Online (Sandbox Code Playgroud)
你知道每种方法有哪些优点和缺点?或者只有执行速度很重要?我的意思nameof是const在编译后将替换为值.
c# ×8
.net ×3
c#-8.0 ×3
c#-6.0 ×1
checkbox ×1
constructor ×1
csproj ×1
css ×1
expression ×1
html ×1
input ×1
jquery ×1
nameof ×1
nuget ×1
onchange ×1
range ×1
static ×1
telegram ×1
telegram-bot ×1
webactivator ×1