我正在使用以下代码在C#文件中创建字典:
private readonly Dictionary<string, XlFileFormat> FILE_TYPE_DICT
= new Dictionary<string, XlFileFormat>
{
{"csv", XlFileFormat.xlCSV},
{"html", XlFileFormat.xlHtml}
};
Run Code Online (Sandbox Code Playgroud)
new
错误下面有一条红线:
无法使用功能'集合initilializer',因为它不是ISO-2 C#语言规范的一部分
谁能解释一下这里发生了什么?
编辑:好的,所以事实证明我使用的是.NET版本2.
UPDATE
从C#6开始,这个问题的答案是:
SomeEvent?.Invoke(this, e);
Run Code Online (Sandbox Code Playgroud)
我经常听到/阅读以下建议:
在检查事件之前,请务必复制事件null
并将其触发.这将消除线程的潜在问题,其中事件变为null
位于您检查null和触发事件的位置之间的位置:
// Copy the event delegate before checking/calling
EventHandler copy = TheEvent;
if (copy != null)
copy(this, EventArgs.Empty); // Call any handlers on the copied list
Run Code Online (Sandbox Code Playgroud)
更新:我从阅读中了解到这可能还需要事件成员的优化,但Jon Skeet在他的回答中指出CLR不会优化副本.
但同时,为了解决这个问题,另一个线程必须做到这样的事情:
// Better delist from event - don't want our handler called from now on:
otherObject.TheEvent -= OnTheEvent;
// Good, now we can be certain that OnTheEvent will not run...
Run Code Online (Sandbox Code Playgroud)
实际的顺序可能是这种混合物:
// Copy the event delegate before checking/calling
EventHandler copy …
Run Code Online (Sandbox Code Playgroud) 我遇到了一些代码
public int MaxHealth =>
Memory[Address].IsValid ?
Memory[Address].Read<int>(Offs.Life.MaxHp) :
0;
Run Code Online (Sandbox Code Playgroud)
现在我对Lambda表达式有点熟悉了.我只是没有看到它以这种方式使用它.
上述陈述与之间的区别是什么?
public int MaxHealth = x ? y:z;
Run Code Online (Sandbox Code Playgroud) 我正在寻找git commit --amend
Mercurial 的反向部分,即修改我的工作副本链接的提交的方法.该修订程序的要求是:
如果可能,它不应该要求任何扩展.它不能要求非默认扩展,即没有官方Mercurial安装附带的扩展.
如果修改提交是我当前分支的一个负责人,则不应创建新的头.如果提交不是头,则可以创建新头.
该程序应该是安全的,如果由于任何原因修改失败,我希望在修改之前恢复相同的工作副本和存储库状态.换句话说,如果修改本身可能失败,则应该有一个故障安全过程来恢复工作副本和存储库状态.我指的是修改程序性质的"失败"(例如冲突),而不是与文件系统相关的问题(如访问限制,无法锁定文件进行写入,......) )
更新(1):
更新(2):
我正在通过命令行而不是在Visual Studio 2013中构建项目.注意,我已将项目从Visual Studio 2012升级到2013.项目在IDE中构建良好.另外,我首先完全卸载了VS2012,重新启动并安装了VS2013.我拥有的唯一Visual Studio版本是2013 Ultimate.
ValidateProjects:
39>path_to_project.csproj(245,3): error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
39>Done Building Project "path_to_project.csproj" (Clean target(s)) -- FAILED.
Run Code Online (Sandbox Code Playgroud)
以下是有问题的两条线:
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v12.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
Run Code Online (Sandbox Code Playgroud)
原来的第二行是v10.0,但我手动将其更改为v12.0.
$(VSToolsPath)从我看到的扩展到v11.0(VS2012)文件夹,显然已不存在了.路径应该是v12.0.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\WebApplications\
Run Code Online (Sandbox Code Playgroud)
我尝试在系统环境变量表中指定VSToolsPath,但外部构建实用程序仍使用v11.0.我尝试在注册表中搜索,但没有提到任何内容.
遗憾的是,我没有看到任何简单的方法来获得使用的确切命令行.我使用构建工具.
思考?
c# web-applications build visual-build-professional visual-studio-2013
我不清楚编译器在需要时如何自动知道编译为64位.它如何知道什么时候可以自信地针对32位?
我很好奇编译器在编译时如何知道要定位的架构.它是否分析代码并根据它发现的内容做出决定?
如何从有向图中找到(迭代)有向图中的所有周期?
例如,我想要这样的东西:
A->B->A
A->B->C->A
Run Code Online (Sandbox Code Playgroud)
但不是:B-> C-> B.
有一个提交只是没有用,所以我想放弃它而不从历史中删除它.
我已经从早期版本更新并承诺,从而创建了一个新的头脑.
我没有分支机构,我不想要分支机构,我只想简单地继续使用新的头部,没有花哨,没有合并,没有后顾之忧,只是继续忘记前一个.
我似乎无法找到如何做到这一点,我开始相信它无法完成.我发现的只是关于分支的东西,或者关于合并的东西.
我正在移动构建过程以使用mercurial并希望将工作目录恢复到最新修订的状态.早期的构建过程运行将修改一些文件并添加一些我不想提交的文件,因此我有本地更改和未添加到存储库的文件.
什么是丢弃所有这些并获得具有最新版本的干净工作目录的最简单方法?
目前我这样做:
hg revert --all
<build command here to delete the contents of the working directory, except the .hg folder.>
hg pull
hg update -r MY_BRANCH
Run Code Online (Sandbox Code Playgroud)
但似乎应该有一个更简单的方法.
我想做的相当于删除repo,进行新的克隆和更新.但是回购太大了,不够快.
c# ×5
mercurial ×3
dictionary ×2
.net ×1
algorithm ×1
build ×1
c#-6.0 ×1
commit ×1
compilation ×1
events ×1
git-amend ×1
graph-theory ×1
pull ×1
vb6 ×1
vba ×1