Tag: C#的

超过2 ^ 32的枚举标志

我在我的应用程序中使用枚举标志。 Enum可以有大约50多个值,所以值可以达到2 ^ 50。 我只是想知道,我可以使用Math.Pow(2, variable)来计算这些? 当我尝试这样做时,我得到一个恒定的编译时错误。 有没有另外一种方法,除了手动计算这些2的权力,并把它? 这是我在做什么: [Flags] internal enum RiskStates : long { None = 0, AL = Convert.ToInt64(Math.Pow(2,0)), AK = 2, AZ = 4, AR = 8, CA = 16, CO = 32, CT = 64, DC = 128, DE = 256, FL = 512, GA = 1024, HI = 2048, […]

不能将typesvoid隐式转换为对象。 .NET MVC PartialViewResult

我有以下控制器操作: [ChildActionOnly] public virtual PartialViewResult ListActions(int id) { var actions = meetingActionRepository.GetAllMeetingActions(id); return PartialView(actions); } 而下面的动作链接(使用t4MVC和剃刀语法) <p> @Html.RenderAction(MVC.MeetingActions.ListActions(Model.MeetingId)) </p> 但是这给了我错误: 不能将typesvoid隐式转换为对象 据我可以告诉控制器的行动是好的,那么可以给我这个错误?

设置System.Drawing.Color值

您好如何在System.Drawing.Color.G设置RGB值? 这就像System.Drawing.Color.G=255; 不允许,因为它只读 Property or indexer 'System.Drawing.Color.G' cannot be assigned toit is read only 我只需要通过分配自定义RGB值来创build一个Color对象

在电子邮件中发送内嵌图像

遇到问题通过电子邮件发送图像作为embedded式图像的正文。 图像文件显示为可用的附件,但内嵌图像部分只显示为红色x。 这是我到目前为止 LinkedResource inline = new LinkedResource(filePath); inline.ContentId = Guid.NewGuid().ToString(); MailMessage mail = new MailMessage(); Attachment att = new Attachment(filePath); att.ContentDisposition.Inline = true; mail.From = from_email; mail.To.Add(data.email); mail.Subject = "Client: " + data.client_id + " Has Sent You A Screenshot"; mail.Body = String.Format( "<h3>Client: " + data.client_id + " Has Sent You A Screenshot</h3>" […]

C#6中的长string插值行

我发现,当应用于我现有的代码库的stringFormat调用时,string插值是非常好的,给定通常首选的字段限制,string对于单行很快变得太长。 特别是当插入的expression式很复杂时。 使用格式string,您可以将variables列表分割成多行。 var str = string.Format("some text {0} more text {1}", obj1.property, obj2.property); 有没有人有任何分手这些线路的首选方法? 我想你可以做一些事情: var str = $"some text { obj1.property }" + " more text { obj2.property };

ReSharper抱怨方法可以是静态的,但不是

为什么ReSharper抱怨当一个方法可以变成静态的,但不是? 是因为只有一个静态方法的实例被创build(在types上),从而节省性能?

为什么(是不是真的?)列出<T>实现所有这些接口,而不仅仅是IList <T>?

MSDN List声明: public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable reflection器给出了类似的图片。 List是否真的实现了所有这些(如果是的话)? 我检查过: interface I1 {} interface I2 : I1 {} interface I3 : I2 {} class A : I3 {} class B : I3, I2, I1 {} static void Main(string[] args) { var a = new A(); var a1 = (I1)a; var […]

对象摘要中的NewLine

问候 当为财产/领域/方法等设置摘要是否有可能有一个换行符? /// <summary> /// This is line 1 /// This is line 2 /// </summary> public bool TestLine { get; set; } 当我设置它显示为在鼠标上: bool TestLine This is line 1 This is line 2 但我希望它显示为: bool TestLine This is line 1 This is line 2 我已经尝试使用\n但是这不起作用。 有没有办法做到这一点?

引用危险是否引发exception?

请看下面的exception抛出和捕获: void some_function() { throw std::exception("some error message"); } int main(int argc, char **argv) { try { some_function(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; exit(1); } return 0; } 通过引用来捕捉抛出的exception是否安全? 我的担心是因为exceptione实际上放置在 some_function() 的堆栈上。 但是some_function()刚刚返回,导致e被破坏。 所以现在实际上e指向一个被破坏的对象。 我关心的是正确的吗? 传递exception但不按值复制的正确方法是什么? 我应该抛出new std::exception()所以它被放置在dynamic内存?

使用隐式types局部variables

我刚刚安装了ReSharper的试用版本,我注意到的第一件事情是,它总是build议用隐式types的types来replace显式的局部variables,例如: public string SomeMethod(int aParam) { int aNumber = SomeOtherMethod(aParam); // should be changed to: var aNumber = SomeOtherMethod(aParam); } 我认为明确的typesvariables更可读(更明确)。 你对ReSharper的build议有什么看法? 使用隐式typesvariables有什么好处吗? 什么时候使用隐式/显式variables?