示例(注意案例):
string s = "Hello world!";
String s = "Hello world!";
Run Code Online (Sandbox Code Playgroud)
每种使用的准则是什么?有什么区别?
当我遇到Joel Spolsky时,我正在阅读更多关于Joel on Software的文章,说明一种特定类型的程序员知道a 和Java/C#(面向对象编程语言)之间的区别.intInteger
那么区别是什么呢?
是什么区别int,System.Int16,System.Int32和System.Int64其他比自己的尺寸?
正在浏览.NET Framework Reference Source的 .NET源代码,只是为了它的乐趣.并找到了一些我不明白的东西.
有一个Int32.cs文件,其中包含Int32类型的C#代码.不知怎的,这对我来说似乎很奇怪.C#编译器如何编译Int32类型的代码?
public struct Int32: IComparable, IFormattable, IConvertible {
internal int m_value;
// ...
}
Run Code Online (Sandbox Code Playgroud)
但这在C#中不是非法的吗?如果int只是别名 Int32,则无法使用错误CS0523进行编译:
'struct1'类型的struct成员'struct2字段'在struct布局中导致循环.
编译器中有一些魔法,还是我完全偏离轨道?
如果int是同义词的Int32原因
enum MyEnum : Int32
{
Value = 1
}
Run Code Online (Sandbox Code Playgroud)
......不编译?在哪里
enum MyEnum : int
{
Value = 1
}
Run Code Online (Sandbox Code Playgroud)
即使将光标悬停在int字上,也会显示struct System.Int32?
在我的C#源代码中,我可能已将整数声明为:
int i = 5;
Run Code Online (Sandbox Code Playgroud)
要么
Int32 i = 5;
Run Code Online (Sandbox Code Playgroud)
在目前流行的32位世界中,它们是等价的.但是,当我们进入64位世界时,我是否正确地说以下内容会变得相同?
int i = 5;
Int64 i = 5;
Run Code Online (Sandbox Code Playgroud) 试图弄清楚它是否最好使用,ExecuteScalar或者ExecuteNonQuery我是否想要返回新插入行的标识列.我已经阅读了这个问题并且我理解那里的差异,但是当我查看几周前我写的一些代码时(虽然从这个网站大量借用)我发现在我使用的插件中ExecuteScalar,就像这样:
public static int SaveTest(Test newTest)
{
var conn = DbConnect.Connection();
const string sqlString = "INSERT INTO dbo.Tests ( Tester , Premise ) " +
" VALUES ( @tester , @premise ) " +
"SET @newId = SCOPE_IDENTITY(); ";
using (conn)
{
using (var cmd = new SqlCommand(sqlString, conn))
{
cmd.Parameters.AddWithValue("@tester", newTest.tester);
cmd.Parameters.AddWithValue("@premise", newTest.premise);
cmd.Parameters.Add("@newId", SqlDbType.Int).Direction = ParameterDirection.Output;
cmd.CommandType = CommandType.Text;
conn.Open();
cmd.ExecuteScalar();
return (int) cmd.Parameters["@newId"].Value;
}
}
}
Run Code Online (Sandbox Code Playgroud)
这对我需要的东西很好,所以我很想知道
ExecuteNonQuery …给出这样的结构:
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; }
}
Run Code Online (Sandbox Code Playgroud)
当然,会生成一个编译器错误,其中包含"this"对象在分配所有字段之前无法使用.
有没有办法为支持字段或属性本身分配值,或者我是否必须使用我自己的显式支持字段以老式方式实现属性?
执行AJAX请求时,我收到以下错误:
将值{null}转换为类型'System.Int32'时出错.路径'[5] .tabID',第1行,第331位.
错误发生在我的第二行 processRequest (...)
public void ProcessRequest (HttpContext context) {
string strJson = new StreamReader(context.Request.InputStream).ReadToEnd();
List<ElementToUpdate> elements = JsonConvert.DeserializeObject<List<ElementToUpdate>>(strJson);
// (...)
}
Run Code Online (Sandbox Code Playgroud)
调试器说这个内容strJson:
[{
"bmk": "132M1",
"state": "off",
"type": "motor",
"tabID": 8
}, {
"bmk": "158M1",
"state": "off",
"type": "motor",
"tabID": 8
}, {
"bmk": "194M1",
"state": "off",
"type": "motor",
"tabID": 8
}, {
"bmk": "198M1",
"state": "on",
"type": "motor",
"tabID": 8
}, {
"bmk": "202M1",
"state": "off",
"type": "motor",
"tabID": 8
}, {
"bmk": "test-m", …Run Code Online (Sandbox Code Playgroud)