What is the difference between an int and an Integer in Java and C#?

I was reading More Joel on Software when I came across Joel Spolsky saying something about a particular type of programmer knowing the difference between an int and an Integer in Java/C# (Object Oriented Programming Languages). So, what is the difference? In Java, the 'int' type is a primitive , whereas the 'Integer' type is an object. In C#, the 'int' type is the sa

Java和C#中的int和Integer有什么区别?

当我遇到Joel Spolsky在谈论某种类型的程序员知道int / int和Integer在Java / C#(面向对象编程语言)之间的区别时,我正在阅读更多Joel on Software。 那么区别是什么呢? 在Java中, 'int'类型是一个基元,而'Integer'类型是一个对象。 在C#中, 'int'类型与System.Int32相同,并且是一个值类型(即更像Java'int')。 一个整数(就像任何其他值类型)可以装箱(“包装”)到一个对象中

Is System.Int32 any slower than using int?

Possible Duplicate: C#, int or Int32? Should I care? Couple of questions on System.Int32: Is there any specific technical reason why sizeof(System.Int32) is not allowed? How fast or slow is System.Int32 in comparison to int type? Calling System.Runtime.InteropServices.Marshal.SizeOf on a variable of type System.Int32 results in 4; how does this work? Would the size of this class be e

System.Int32比使用int慢吗?

可能重复: C#,int或Int32? 我应该在乎吗? System.Int32上的几个问题: sizeof(System.Int32)不允许有任何特定的技术原因吗? System.Int32与int类型相比有多快或多慢? 对System.Int32类型的变量调用System.Runtime.InteropServices.Marshal.SizeOf的结果为4; 这个怎么用? 这个类的大小是否与int的大小完全相同? 有效地没有区别。 int == Int32 。 前者隐含32位,而Int32拼出来,类似Int64和Int16(

Use "int" or "Int32" while type casting?

Possible Duplicate: C#, int or Int32? Should I care? I'm using GetPosition(this) when MouseMoved event gets triggered so having: Point pt = e.GetPosition(this); As far as I see both following type casts work but which one is recommended and why? int x = (int)pt.X; int x = (Int32)pt.X; They do exactly the same thing - they'll even compile to the same IL. (Assuming you haven't

在类型转换时使用“int”或“Int32”?

可能重复: C#,int或Int32? 我应该在乎吗? 当MouseMoved event被触发时,我使用GetPosition(this) ,因此具有: Point pt = e.GetPosition(this); 据我看到,下面的类型转换工作,但建议哪一个,为什么? int x = (int)pt.X; int x = (Int32)pt.X; 他们完全一样 - 甚至会编译成相同的IL。 (假设你还没有其他的Int32类型的其他类型的...) int只是global::System.Int32的别名。 (这不仅适用于投射 - 它几乎可

Advantages/disadvantages of int and Int32

This question already has an answer here: Should I use int or Int32 34 answers They are in fact one and the same -- both declare 32-bit integers, and for the most part their behavior will be identical. The shorthand int is just an alias for the Int32 system type. From the language specification: 4.1.4 Simple Types C# provides a set of predefined struct types called the simple types. T

int和Int32的优缺点

这个问题在这里已经有了答案: 我应该使用int还是Int32 34答案 它们实际上是一样的 - 都声明32位整数,并且在大多数情况下它们的行为将是相同的。 简写int只是Int32系统类型的别名。 从语言规范: 4.1.4简单类型 C#提供了一组预定义的结构类型,称为简单类型。 简单类型通过保留字标识,但这些保留字只是System命名空间中预定义结构类型的别名,如下表所述。 以下是简单类型及其别名的列表: Reserved word Al

MSIL of System.Int32 and int will be same?

Possible Duplicate: C#, int or Int32? Should I care? Please any one let me know MSIL of System.Int32 and int will be same or different, If different then which one we should use. Edit: this won't compile public enum MyEnum : Int32 { AEnum = 0 } but this will public enum MyEnum : int { AEnum = 0 } int is an alias for System.Int32 , they are completely the same. enums on

System.Int32和int的MSIL是否一样?

可能重复: C#,int或Int32? 我应该在乎吗? 请任何一个让我知道System.Int32的MSIL和int将相同或不同,如果不同,那么我们应该使用哪一个。 编辑: 这不会编译 public enum MyEnum : Int32 { AEnum = 0 } 但这会 public enum MyEnum : int { AEnum = 0 } int是System.Int32的别名,它们完全相同。 enums只能将整型类型作为类型,否则这将是可能的: using Int32 = System.String; public enum Somet

C# If Equals Case insensitive

This question already has an answer here: Comparing two strings, ignoring case in c# [duplicate] 8 answers You could use this string.Equals(one, two, StringComparison.CurrentCultureIgnoreCase) Your code would be if (string.Equals(one, two, StringComparison.CurrentCultureIgnoreCase)) { MessageBox.Show("Pass"); } else { MessageBox.Show("Fail"); } Using CurrentCultureIgnoreCase : Com

C#如果等于大小写不敏感

这个问题在这里已经有了答案: 比较两个字符串,忽略大小写在c#中[复制] 8个答案 你可以使用这个 string.Equals(one, two, StringComparison.CurrentCultureIgnoreCase) 你的代码是 if (string.Equals(one, two, StringComparison.CurrentCultureIgnoreCase)) { MessageBox.Show("Pass"); } else { MessageBox.Show("Fail"); } 使用CurrentCultureIgnoreCase : 使用文化敏感的排序规则比较字符串,当前的文化

Case insensitive LIKE condition in LINQ (with Regular Expression)

I have following code that works if the search text and the items in the list are of same case (lower case / upper case). If there is a mixed casing it is not working,. How can we make it case insensitive search. var text = "c"; var myStrings = new List<string>() { "Aa", "ACB", "cc" }; var regEx = new System.Text.RegularExpressions.Regex(text); var results = myStrings .Where<s

LINQ中不区分大小写LIKE条件(使用正则表达式)

如果搜索文本和列表中的项目是相同的大小写(小写/大写),我有以下代码可用。 如果有混合外壳,它不起作用。 我们如何使它不区分大小写的搜索。 var text = "c"; var myStrings = new List<string>() { "Aa", "ACB", "cc" }; var regEx = new System.Text.RegularExpressions.Regex(text); var results = myStrings .Where<string>(item => regEx.IsMatch(item)) .ToList<string>();

Why must we define both == and != in C#?

The C# compiler requires that whenever a custom type defines operator == , it must also define != (see here). Why? I'm curious to know why the designers thought it necessary and why can't the compiler default to a reasonable implementation for either of the operators when only the other is present. For example, Lua lets you define only the equality operator and you get the other for

为什么我们必须在C#中定义==和!=?

C#编译器要求每当自定义类型定义运算符== ,它也必须定义!= (请参见此处)。 为什么? 我很想知道为什么设计者认为它是必需的,为什么编译器默认为只有另一个运行时才有合理的实现。 例如,Lua允许您只定义相等运算符,并免费获得其他运算符。 C#可以通过要求你定义==或者== ==和!=然后自动编译缺少的!=运算符为!(left == right)来做同样的事情。 我知道有些怪异的角落案例,其中一些实体可能既不平等又不平等(如I

Make first letter of a string upper case (with maximum performance)

I have a DetailsView with a TextBox and I want the input data be saved always with the FIRST LETTER IN CAPITAL. Example: "red" --> "Red" "red house" --> " Red house" How can I achieve this maximizing performance ? NOTE : Based on the answers and the comments under the answers, many people think this is asking about capitalizing all words in the string. Eg => Red House It isn'

使字符串大写的第一个字母(具有最高性能)

我有一个带有TextBox的DetailsView ,我希望输入的数据总是以首字母大写保存。 例: "red" --> "Red" "red house" --> " Red house" 我怎样才能达到这个最大化的表现 ? 注意 : 根据答案和答案下的评论,很多人认为这是要求将字符串中的所有单词大写。 Eg => Red House 它不是,但如果这是你想要的 ,找一个使用TitleInfo的ToTitleCase方法的答案。 (注意:对于实际提出的问题,这些答案不正确。) 请参

Converting string to title case

I have a string which contains words in a mixture of upper and lower case characters. For example: string myData = "a Simple string"; I need to convert the first character of each word (separated by spaces) into upper case. So I want the result as: string myData ="A Simple String"; Is there any easy way to do this? I don't want to split the string and do the conver

将字符串转换为标题大小写

我有一个字符串,其中包含大写和小写字符混合的单词。 例如: string myData = "a Simple string"; 我需要将每个单词的首字符(用空格分隔)转换为大写。 所以我想要的结果为: string myData ="A Simple String"; 有没有简单的方法来做到这一点? 我不想分割字符串并进行转换(这将是我的最后手段)。 另外,保证字符串是英文的。 MSDN:TextInfo.ToTitleCase 确保你包含: using System.Glob