Should 'using' be inside the namespace or outside?

Possible Duplicate: Should Usings be inside or outside the namespace Are there any technical reasons for preferring this namespace Foo { using System; using System.IO; instead of the default using System; using System.IO; namespace Foo { Eric Lippert explains this. In general, they're identical. However, using statements in the namespace can see namespaces and aliases i

“使用”应该放在命名空间还是外部?

可能重复: 应该使用命名空间内部还是外部 是否有任何技术上的原因喜欢这个 namespace Foo { using System; using System.IO; 而不是默认值 using System; using System.IO; namespace Foo { Eric Lippert解释说。 一般来说,它们是相同的。 但是,在名称空间中using语句可以看到名称空间外部包含的名称空间和别名。 几乎*两者之间唯一的区别是如果您在同一个文件中使用了多个命名空间(或者如果您多次

.NET JIT potential error?

The following code gives different output when running the release inside Visual Studio, and running the release outside Visual Studio. I'm using Visual Studio 2008 and targeting .NET 3.5. I've also tried .NET 3.5 SP1. When running outside Visual Studio, the JIT should kick in. Either (a) there's something subtle going on with C# that I'm missing or (b) the JIT is actually in

.NET JIT潜在错误?

在Visual Studio中运行发行版并在Visual Studio外运行发行版时,以下代码提供了不同的输出。 我正在使用Visual Studio 2008并以.NET 3.5为目标。 我也尝试过.NET 3.5 SP1。 当在Visual Studio外部运行时,JIT应该启动。或者(a)C#中存在一些细微的缺失,或者(b)JIT实际上是错误的。 我怀疑JIT可能会出错,但我已经没有其他可能性了... 在Visual Studio中运行时输出: 0 0, 0 1, 1 0, 1 1, 在Visual

Why do primitive data types work without including the System namespace?

I read that all primitives fall under the System namespace. If I comment out using System , I would expect there to be a build error in my program. However, it is running successfully. Why is this? It's because int is an alias for System.Int32 , and since the "Int32" is already prefixed with its namespace (ie. "fully qualified"), the syntax is legal without having to

为什么基元数据类型在不包含System命名空间的情况下工作?

我读过所有的原语属于System命名空间。 如果我using System注释掉,我期望在我的程序中出现构建错误。 但是,它正在成功运行。 为什么是这样? 这是因为int是System.Int32的别名,并且由于“Int32”已经以其名称空间作为前缀(即“完全限定”),所以该语法是合法的,而不必指定using System; 在代码的顶部。 下面的MSDN代码片段描述了这个概念 - 大多数C#应用程序都以一段使用指令开始。 本节列出应用程序将频繁使用的

How do I get from a type to the TryParse method?

My particular problem: I have a string which specifies an aribitrary type in a configuration class Config.numberType = "System.Foo"; where Foo is a type like Decimal or Double I use Type.GetType(Config.numberType) to return the corresponding type. How do I get from that type to being able to use, System.Foo.TryParse() ? Some further related queries TryParse() can be access

如何从一个类型到TryParse方法?

我特别的问题: 我有一个字符串,它指定了配置类中的任意类型 Config.numberType = "System.Foo"; Foo是类似Decimal或Double的类型 我使用Type.GetType(Config.numberType)来返回相应的类型。 我如何从这种类型获得可以使用的System.Foo.TryParse() ? 一些进一步的相关查询 可以从System.Foo.TryParse()和foo.TryParse()访问TryParse() foo.TryParse() 。 这是否意味着foo是C#中的某种类? 这对我来

How can I set the value of auto property backing fields in a struct constructor?

Given a struct like this: public struct SomeStruct { public SomeStruct(String stringProperty, Int32 intProperty) { this.StringProperty = stringProperty; this.IntProperty = intProperty; } public String StringProperty { get; set; } public Int32 IntProperty { get; set; } } Of course, a compiler error is generated that reads The 'this' object cannot be u

我怎样才能设置结构构造函数中的自动属性支持字段的值?

给定一个像这样的结构: public struct SomeStruct { public SomeStruct(String stringProperty, Int32 intProperty) { this.StringProperty = stringProperty; this.IntProperty = intProperty; } public String StringProperty { get; set; } public Int32 IntProperty { get; set; } } 当然,会产生一个编译器错误,读取'this'对象在其所有字段分配给它之前无法使用 。 有

What is the difference between uint and System.UInt32?

有区别,还是只是别名? Yes, they are aliases. Here's the full list. 他们是别名没有区别。 它们是别名,但是: enum A : uint { // This code compiles } enum A : UInt32 { // Compile error }

uint和System.UInt32有什么区别?

有区别,还是只是别名? 是的,他们是别名。 这是完整的列表。 他们是别名没有区别。 它们是别名,但是: enum A : uint { // This code compiles } enum A : UInt32 { // Compile error }

C# int, Int32 and enums

If int is synonymous to Int32 why does enum MyEnum : Int32 { Value = 1 } ...not compile? Where as enum MyEnum : int { Value = 1 } will, even though hovering the cursor over the int word will display struct System.Int32? The underlying type is indeed the same, but the compiler depends on the type to be as the exact alias. This is a compilation error based on parsing. I took a look

C#int,Int32和枚举

如果int与Int32同义,为什么呢 enum MyEnum : Int32 { Value = 1 } ...不编译? 在哪里 enum MyEnum : int { Value = 1 } 即使将光标悬停在整数字上,也会显示结构System.Int32? 基础类型确实是相同的,但编译器依赖于类型作为确切的别名。 这是基于解析的编译错误。 我看了一下C#语法规范和基于别名定义的基础类型(如'int','unit'...等等)。 解析器期望整型类型语法规则中的特定字符串

If Int32 is just an alias for int, how can the Int32 class use an int?

Been browsing through .NET source code of .NET Framework Reference Source, just for fun of it. And found something I don't understand. There is a Int32.cs file with C# code for Int32 type. And somehow that seems strange to me. How does the C# compiler compile code for Int32 type? public struct Int32: IComparable, IFormattable, IConvertible { internal int m_value; // ... } But

如果Int32只是int的别名,那么Int32类如何使用int?

一直在浏览.NET Framework Reference Source的.NET源代码,只是为了好玩。 发现了一些我不明白的东西。 有一个Int32.cs文件,其中包含用于Int32类型的C#代码。 不知何故,这对我来说似乎很陌生。 C#编译器如何编译Int32类型的代码? public struct Int32: IComparable, IFormattable, IConvertible { internal int m_value; // ... } 但在C#中这不是非法的吗? 如果int只是Int32的别名,则它将无法使用错误

Is an int a 64

In my C# source code I may have declared integers as: int i = 5; or Int32 i = 5; In the currently prevalent 32-bit world they are equivalent. However, as we move into a 64-bit world, am I correct in saying that the following will become the same? int i = 5; Int64 i = 5; No. The C# specification rigidly defines that int is an alias for System.Int32 with exactly 32 bits. Changing this would

是一个int 64

在我的C#源代码中,我可能已经将整数声明为: int i = 5; 要么 Int32 i = 5; 在当前流行的32位世界中,它们是相同的。 然而,当我们进入一个64位的世界时,我是否正确地说以下内容会变得相同? int i = 5; Int64 i = 5; 不.C#规范严格地定义了int是System.Int32一个别名,正好是32位。 改变这将是一个重大的突破性改变。 C#中的int关键字被定义为System.Int32类型的别名,这是(根据名称判断的)意思是一个32位整数

What is the difference between int, Int16, Int32 and Int64?

int , System.Int16 , System.Int32和System.Int64除了它们的大小之外有什么区别? Each type of integer has a different range of storage capacity Type Capacity Int16 -- (-32,768 to +32,767) Int32 -- (-2,147,483,648 to +2,147,483,647) Int64 -- (-9,223,372,036,854,775,808 to +9,223,372,036,854,775,807) As stated by James Sutherland in his answer: int and Int32 are indeed synon

int,Int16,Int32和Int64有什么区别?

int , System.Int16 , System.Int32和System.Int64除了它们的大小之外有什么区别? 每种类型的整数具有不同的存储容量范围 Type Capacity Int16 -- (-32,768 to +32,767) Int32 -- (-2,147,483,648 to +2,147,483,647) Int64 -- (-9,223,372,036,854,775,808 to +9,223,372,036,854,775,807) 正如James Sutherland在他的回答中所述: int和Int32确实是同义词; int会更加熟悉, Int32使32位对读取代