I'm trying to find a reference for the default visibility of various aspects of C#. Class types, fields, methods, enums, etc. Can someone provide a list of these along with their default visibility (ie, no prefixed modifier)? All of the information you are looking for can be found here and here (thanks Reed Copsey): From the first link: Classes and structs that are declared directly
我试图找到C#各个方面默认可见性的参考。 类的类型,字段,方法,枚举等 有人可以提供这些列表以及它们的默认可见性(即没有前缀修饰符)吗? 所有您要查找的信息都可以在这里和这里找到(感谢Reed Copsey): 从第一个链接: 直接在名称空间内声明的类和结构 (换言之,不嵌套在其他类或结构中)可以是公共的或内部的。 如果未指定访问修饰符,则内部是默认值 。 ... 类成员和结构成员 (包括嵌套类和结构体)的
I want to know the difference between ObservableCollection and BindingList because I've used both to notify for any add/delete change in Source, but I actually do not know when to prefer one over the other. Why would I choose one of the following over the other? ObservableCollection<Employee> lstEmp = new ObservableCollection<Employee>(); or BindingList<Employee> lstEmp
我想知道ObservableCollection和BindingList之间的区别,因为我已经使用它们来通知Source中的任何添加/删除更改,但实际上我不知道什么时候更喜欢一个。 为什么我会选择以下其中一种? ObservableCollection<Employee> lstEmp = new ObservableCollection<Employee>(); 要么 BindingList<Employee> lstEmp = new BindingList<Employee>(); ObservableCollection可以像任何集合一样从UI更新。 真
why cannot declare const static string inside a class? Have to use static readonly In the C# language (as well as PHP), const is implicitly static , so you don't use both keywords together. This is unlike C and C++ where const doesn't say if a variable is static or not, just that its value is not modifiable. You declare a constant string like this: const string SomeConstant = "abc"
为什么不能在类中声明const静态字符串? 必须使用静态只读 在C#语言(以及PHP)中, const是隐式static ,所以你不要把两个关键字放在一起。 这不像C和C ++,其中const不会说如果一个变量是静态的,只是它的值不可修改。 你声明一个像这样的常量字符串: const string SomeConstant = "abc"; const字段和静态readonly字段之间也有细微差别,但两者都是相似的,因为您无法更改它们的值。 细节在这个问题。 所有常量声
I wish to say: public void Problem(DateTime optional = DateTime.MaxValue) { } But the compiler complains that DateTime.MaxValue is not a compile time constant. DateTime.MinValue is easy, just use default(DateTime) see also "How do I default a parameter to Guid.Empty in C#?" I do not wish to use method overloading, as the method I am trying to tame has 101 parameters! 我会用这个
我想说: public void Problem(DateTime optional = DateTime.MaxValue) { } 但编译器抱怨DateTime.MaxValue不是编译时间常量。 DateTime.MinValue很简单,只需使用default(DateTime) 另请参阅“如何在C#中将参数默认为Guid.Empty?” 我不希望使用方法重载,因为我试图驯服的方法有101个参数! 我会用这个替代这样的东西: public void Problem(DateTime? optional = null) { DateTime dateTime = optional != null
I have a multi threaded application that writes to a settings xml file using a static method. I want to avoid that the file is being updated twice at the same time (causing accesss/write exception). How do I do that? This doesn't work: namespace Program { public class Settings { private static void SetSettingsValue (string settings, string value) { //
我有一个使用静态方法写入设置xml文件的多线程应用程序。 我想避免文件被同时更新两次(导致访问/写入异常)。 我怎么做? 这不起作用: namespace Program { public class Settings { private static void SetSettingsValue (string settings, string value) { // make this thread safe to avoid writing to a locked settings xml file lock (typeof(Settings))
We have a project that's compiled into a DLL called consts.dll that contains something like: public static class Consts { public const string a = "a"; public const string b = "b"; public const string c = "c"; } We have multiple projects of this sort, each compiled into a DLL of the same name (consts.dll) and we replace them according to need. We have another class that uses the
我们有一个编译成名为consts.dll的DLL的项目,它包含如下内容: public static class Consts { public const string a = "a"; public const string b = "b"; public const string c = "c"; } 我们有这种类型的多个项目,每个都编译成一个同名的DLL(consts.dll),我们根据需要替换它们。 我们有另一个使用这些const的类: public class ConstsUser { string f() { return Consts.a; } } 不幸的是, Const
This question already has an answer here: What is the difference between const and readonly? 31 answers Readonly: Can only be set in the constructor. Const: Is a COMPILE TIME CONSTANT. Ie can not be determined at runtime.
这个问题在这里已经有了答案: const和readonly有什么区别? 31个答案 只读:只能在构造函数中设置。 Const:是一个编译时间常数。 即不能在运行时确定。
This question already has an answer here: What is the difference between const and readonly? 31 answers You want to use the readonly modifier private readonly static ReadOnlyCollection<string> _ExtensionsOfInterest = new ReadOnlyCollection<string>() { ".doc", ".docx", ".pdf", ".png", ".jpg" }; EDIT Just noticed that the ReadOnlyCollection type doesnt allow an empty constr
这个问题在这里已经有了答案: const和readonly有什么区别? 31个答案 你想使用readonly修饰符 private readonly static ReadOnlyCollection<string> _ExtensionsOfInterest = new ReadOnlyCollection<string>() { ".doc", ".docx", ".pdf", ".png", ".jpg" }; 编辑 只是注意到ReadOnlyCollection类型不允许空的构造函数或提供括号中的列表。 您必须在构造函数中提供列表。 所以你可以把它写成只读
Possible Duplicate: What is the difference between const and readonly? are these interchangeable? can you show me code on how you would apply the two? No, they aren't. A const field is literal value embedded in the assembly. Only primitive values (strings and numbers) can be const , and they are evaluated at compile time. When you reference a const field, the compiler embeds the
可能重复: const和readonly有什么区别? 这些是可以互换的吗? 你能告诉我如何应用这两个代码吗? 不,他们不是。 const字段是嵌入在程序集中的文字值。 只有原始值(字符串和数字)可以是const ,并且它们在编译时进行评估。 当你引用一个const字段时,编译器嵌入该字段的字面值。 因此,如果使用另一个程序const ,而另一个程序集使用不同的值进行重新编译,则只有在您针对新版本重新编译时,程序集才会使用新
Possible Duplicate: What is the difference between const and readonly? i have doubt in c# what is difference in constant and readonly explain with simple problem or any reference. A const is initialized at compile time, and cannot be changed. A readonly is initialized at runtime, but can be done only one time (in the constructor, or inline declaration). const is a compile-time constant:
可能重复: const和readonly有什么区别? 我有疑问在C#有什么区别在常量和只读解释与简单的问题或任何参考。 const在编译时被初始化,并且不能被改变。 readonly在运行时初始化,但只能执行一次(在构造函数或内联声明中)。 const是一个编译时常量:您编写的值会插入代码中。 这意味着您只能拥有编译器可以理解的常量值类型,例如整数和字符串。 与readonly不同,您不能将函数的结果分配给const字段,例如: class