小编srn*_*dai的帖子

Is there a difference between "double val = 1;" and "double val = 1D;"?

Is there a difference between the following two pieces of code?

class Test {

    public readonly double Val;

    public Test(bool src) {
        this.Val = src ? 1 : 0;
    }

}

class Test {

    public readonly double Val;

    public Test(bool src) {
        this.Val = src ? 1D : 0D;
    }

}
Run Code Online (Sandbox Code Playgroud)

I found that our code base uses the second way of writing.

.net c#

12
推荐指数
2
解决办法
245
查看次数

为什么在C#中定义属性的两种方法会有不同的结果?

在C#中定义属性的两种方法

public class Program {

    public static bool[] Property1 => new bool[1];
    public static bool[] Property2 { get; } = new bool[1];

    public static void Main() {

        Property1[0] = true;
        Property2[0] = true;

        Console.WriteLine($"{Property1[0]} {Property2[0]}");

        Console.ReadLine();

    }

}
Run Code Online (Sandbox Code Playgroud)

这两种方式有不同的结果

假真

c#

2
推荐指数
1
解决办法
54
查看次数

标签 统计

c# ×2

.net ×1