我知道我可以成倍增长但是我不喜欢懒惰的编程.
有没有人设计过一些巫术来自动将枚举作为两个权力?
以下是我要使其具体化的例子:
[Flags]
private enum Targets : uint
{
None = 0,
Campaigns = 1,
CampaignGroups = 2,
Advertisers = 4,
AdvertiserGroups = 8,
AffiliateGroups = 16,
Affiliates = 32,
Creatives = 64,
DetailedLeads = 128,
DetailedSales = 256,
ProgramLeads = 512,
CreativeDeployments = 1024,
CampaignCategories = 2048,
Payouts = 4096,
All = uint.MaxValue
}
Run Code Online (Sandbox Code Playgroud) 有没有办法重写:
var tbl = ds.TABLES;
var q = from c in tbl
select c.TABLE_TYPE;
string s = "";
foreach (var item in q.Distinct())
{
s += "[" + item + "]";
}
MessageBox.Show(s);
Run Code Online (Sandbox Code Playgroud)
那么Distinct()调用是在LINQ查询中?
我已经注意到我的web.config文件中的这一部分了一段时间,我现在试图弄清楚目的是什么:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Run Code Online (Sandbox Code Playgroud)
所以,第一个条目似乎说:
System.Web.Helpers是具有公钥标记的依赖程序集的名称
31bf3856ad364e35.将版本1.0.0.0到2.0.0.0重定向到版本2.0.0.0.
我最好的猜测是,它意味着在ASP.NET运行时上下文中执行的任何代码依赖于具有指定名称的程序集,该程序集也具有指定范围内的版本,就好像它是使用指定版本编译的一样执行指定的公钥.
这是否意味着如果我有一个依赖于类库的Web项目,并且该类库引用了具有aa bindingRedirect的旧版程序集,那么代码将执行就好像它是针对较新版本编译的一样?
如果我在VS2010中有一个项目,我已经使用nuget添加了许多软件包,那么我可以在该解决方案中创建另一个项目并以某种方式获得完全相同的软件包配置吗?
这很容易解决,但我只是好奇我是否可以使用语言功能,或者可能是语言不允许这意味着我在课堂设计中犯了一个逻辑错误.
我正在对我的代码进行自我审查,以帮助"强化"它以便重复使用,我刚刚来到:
public partial class TrackTyped : Component
{
IContainer components = null;
public TrackTyped()
: base()
{
InitializeComponent();
}
public TrackTyped(IContainer container)
: base()
{
container.Add(this);
InitializeComponent();
}
}
Run Code Online (Sandbox Code Playgroud)
当我在两个构造函数中看到相同的代码行时,我通常会做的是使用"this()"调用另一个代码,但我似乎无法做到.
如果我正确阅读规范(我刚开始尝试阅读规范,所以我可能不对):
10.11 Instance Constructors
constructor-declarator:
identifier ( formal-parameter-listopt ) constructor-initializeropt
constructor-initializer:
: base ( argument-listopt )
: this ( argument-listopt )
Run Code Online (Sandbox Code Playgroud)
它说我只能有其中一个.
问题:10.11意味着没有理由需要同时调用它们,还是只是暗示语言只支持调用它?
如何在桌面应用程序中使用一个按钮,使用户的默认浏览器启动并显示应用程序逻辑提供的URL.
这可能是一个很好的观点,但它涉及编译器在您执行以下操作时发出的警告:
class A
{
public virtual void F() { }
}
class B : A
{
public void F() { }
}
Run Code Online (Sandbox Code Playgroud)
然后你得到警告:
'EomApp1.B.F()' hides inherited member 'EomApp1.A.F()'.
To make the current member override that implementation, add the override keyword. Otherwise use the new keyword.

问题:如果我什么都不做的话,警告我会发生什么警告?如果我添加'new'关键字,那么我的程序功能是否会有所不同?
(注意:我知道我可以很容易地测试这个,但我觉得这里值得问一下)
我猜它既不调用csc.exe也不实现整个编译器,所以它是如何工作的?
更新:感谢Jon Skeet指向易于学习的代码.
string c = @"
public class A
{
public static void Main(string[] args)
{
System.Console.WriteLine(""hello world"");
}
}
";
CodeDomProvider compiler = new CSharpCodeProvider();
CompilerParameters parameters = new CompilerParameters();
parameters.WarningLevel = 4;
parameters.GenerateExecutable = false;
parameters.GenerateInMemory = true;
CompilerResults r = compiler.CompileAssemblyFromSource(parameters, c);
Assembly a = r.CompiledAssembly;
Type[] ts = a.GetTypes();
Type t = ts[0];
object o = t.GetMethod("Main").Invoke(null, new object[] { new string[] { } });
Run Code Online (Sandbox Code Playgroud) 不起作用:
Func<string, byte[]> getFileContents = (Mode != null && Mode.ToUpper() == "TEXT")
? TextFileContents
: BinaryFileContents;
private static byte[] BinaryFileContents(string file)
{
return System.IO.File.ReadAllBytes(file);
}
private static byte[] TextFileContents(string file)
{
using (var sourceStream = new StreamReader(file))
{
return Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
}
}
Run Code Online (Sandbox Code Playgroud)
错误是
方法组和方法组之间没有隐式转换
作品:
Func<string, byte[]> getFileContents2;
if (Mode != null && Mode.ToUpper() == "TEXT")
{
getFileContents2 = TextFileContents;
}
else
{
getFileContents2 = BinaryFileContents;
}
Run Code Online (Sandbox Code Playgroud)
我只是好奇为什么?我错过了什么吗?
我正在查看Type的元数据,并注意到一个成员受到保护,这让我想知道它可能从中得到什么,这让我意识到我可以编写一个源自它的类,这一切让我想知道我能做些什么与此(如果有的话).
以下没有编译器错误:
class MyType : Type
{
// Implemented abstract members here.
}
Run Code Online (Sandbox Code Playgroud) c# ×9
asp.net ×1
browser ×1
constructor ×1
enums ×1
inheritance ×1
lambda ×1
linq ×1
linqpad ×1
nuget ×1
types ×1
warnings ×1
web-config ×1