Tag: C#的

在C#中访问Process.MainModule.FileName时如何避免Win32exception?

我开始了一个新的项目,列出所有正在运行的进程的完整path。 当访问一些进程时,程序崩溃并抛出一个Win32Exception 。 说明中列出了列出stream程模块时发生的错误。 最初我以为这个问题可能会发生,因为我在64位平台上运行它,所以我重新编译了CPUtypesx86和AnyCPU 。 不过,我也遇到了同样的错误。 Process p = Process.GetProcessById(2011); string s = proc_by_id.MainModule.FileName; 错误发生在第2行。 空白字段显示出现错误的进程: 有没有办法解决这个错误信息?

如何检查operator ==是否存在?

我想创build一个例子,这将检查operator== (成员或非成员函数)的存在。 要检查一个类是否有成员operator==很容易,但是如何检查它是否有一个非成员operator== ? 这就是我所需要的: #include <iostream> struct A { int a; #if 0 bool operator==( const A& rhs ) const { return ( a==rhs.a); } #endif }; #if 1 bool operator==( const A &l,const A &r ) { return ( la==ra); } #endif template < typename T > struct opEqualExists { struct yes{ char […]

创build复合关键entity framework

不久之后,我想在我的表上创build复合键,并保留主键,以提高sql server的search性能。 每当我search一个没有主键的实体(即一串GUID)时,性能问题就出现在200k数据表上。 假设我有三个class public class Device{ public int ID { get; set; } public string UDID { get; set; } public string ApplicationKey { get; set; } public string PlatformKey { get; set; } public ICollection<NotificationMessageDevice> DeviceMessages { get; set; } } public class NotificationMessageDevice { [Column(Order = 0), Key, ForeignKey("NotificationMessage")] public int NotificationMessage_ID […]

如何运行没有插件和所有第三方function的视觉工作室

我在我的visual studio中安装了许多第三方插件加载项。 现在我想运行一个没有所有插件插件和第三方function的Visual Studio的实例 就像Mozilla Firefox一样 我怎么能运行没有所有插件或附加组件的Visual Studio。 是他们的任何方法存在像其他应用程序

@ Html.HiddenFor在ASP.NET MVC的列表中不起作用

我正在使用包含List作为属性的模型。 我使用从SQL Server获取的项来填充这个列表。 我希望列表隐藏在视图中并传递给POST操作。 后来我可能想用jQuery将更多的项目添加到这个列表,这使得数组不适合以后的扩展。 通常你会使用 @ Html.HiddenFor(model => model.MyList) 要完成这个function,但由于某种原因,POST中的List始终为空。 很简单的问题,任何人都知道为什么MVC的行为是这样的?

Linq以实体,随机顺序

如何以随机顺序返回匹配实体? 只是要清楚这是entity framework的东西和LINQ到实体。 (空码) IEnumerable<MyEntity> results = from en in context.MyEntity where en.type == myTypeVar orderby ????? select en; 谢谢 编辑: 我试图将其添加到上下文中: public Guid Random() { return new Guid(); } 并使用此查询: IEnumerable<MyEntity> results = from en in context.MyEntity where en.type == myTypeVar orderby context.Random() select en; 但是我得到这个错误: System.NotSupportedException: LINQ to Entities does not recognize the […]

切换大小写typesC#

可能重复: C# – 有没有比这更好的替代“打开types”? 你好,假设我得到一个大的if / else类types。 有一种方法可以用开关盒来做到这一点? 例如: function test(object obj) { if(obj is WebControl) { }else if(obj is TextBox) { } else if(obj is ComboBox) { } 等等 我想创build类似的东西 switch(obj) { case is TextBox: break; case is ComboBox: break; } }

(types)值和types(值)之间有什么区别?

有什么区别 (type)value 和 type(value) 在C ++?

为什么匿名types等于实现比较字段?

就像问题一样,我只是想知道为什么语言的devise者们希望在匿名types上实现Equals,就像价值types一样。 这不是误导吗? class Person { public string Name { get; set; } public int Age { get; set; } } public static void ProofThatAnonymousTypesEqualsComparesBackingFields() { var personOne = new { Name = "Paweł", Age = 18 }; var personTwo = new { Name = "Paweł", Age = 18 }; Console.WriteLine(personOne == personTwo); // false Console.WriteLine(personOne.Equals(personTwo)); […]

禁用单个警告错误

有没有办法使用Visual Studio在cpp文件中禁用单个警告行? 例如,如果我捕捉到一个exception,而不处理它,我得到错误4101(未引用的本地variables)。 有没有办法忽略这个function,但否则在编译单元报告呢? 目前,我把#pragma warning (disable : 4101)放在文件的顶部,但显然只是closures整个单元。