相关疑难解决方法(0)

C#中字符串和字符串有什么区别?

示例(注意案例):

string s = "Hello world!";
String s = "Hello world!";
Run Code Online (Sandbox Code Playgroud)

每种使用的准则是什么?有什么区别

.net c# string alias types

6250
推荐指数
62
解决办法
103万
查看次数

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

当我遇到Joel Spolsky时,我正在阅读更多关于Joel on Software的文章,说明一种特定类型的程序员知道a 和Java/C#(面向对象编程语言)之间的区别.intInteger

那么区别是什么呢?

c# java int integer

256
推荐指数
14
解决办法
24万
查看次数

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

是什么区别int,System.Int16,System.Int32System.Int64其他比自己的尺寸?

.net c#

213
推荐指数
10
解决办法
44万
查看次数

如果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;

    // ... 
}
Run Code Online (Sandbox Code Playgroud)

但这在C#中不是非法的吗?如果int只是别名 Int32,则无法使用错误CS0523进行编译:

'struct1'类型的struct成员'struct2字段'在struct布局中导致循环.

编译器中有一些魔法,还是我完全偏离轨道?

c# compiler-construction internals

56
推荐指数
2
解决办法
3043
查看次数

C#int,Int32和enums

如果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?

.net c# int enums int32

33
推荐指数
2
解决办法
5106
查看次数

int是64位C#中的64位整数吗?

在我的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)

c# 64-bit primitive 32-bit

28
推荐指数
5
解决办法
8910
查看次数

返回标识值时,ExecuteScalar vs ExecuteNonQuery

试图弄清楚它是否最好使用,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)

这对我需要的东西很好,所以我很想知道

  1. 我是否应该在ExecuteNonQuery …

c# sql-server executescalar executenonquery

22
推荐指数
1
解决办法
7万
查看次数

如何在结构构造函数中设置自动属性支持字段的值?

给出这样的结构:

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"对象在分配所有字段之前无法使用.

有没有办法为支持字段或属性本身分配值,或者我是否必须使用我自己的显式支持字段以老式方式实现属性?

c# constructor struct backing-field

19
推荐指数
1
解决办法
3752
查看次数

为什么原始数据类型在不包含System名称空间的情况下工作

我读到所有原语都属于System命名空间.如果我发表评论using System,我希望我的程序中存在构建错误.但是,它正在成功运行.为什么是这样?

附上我的示例程序的快照.

.net c# primitive namespaces

19
推荐指数
2
解决办法
906
查看次数

Newtonsoft Json将值{null}转换为类型'System.Int32'时出错

执行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)

.net c# json json.net deserialization

14
推荐指数
2
解决办法
3万
查看次数