相关疑难解决方法(0)

任何人都可以用C#中的签名浮点数解释这种奇怪的行为吗?

以下是带注释的示例:

class Program
{
    // first version of structure
    public struct D1
    {
        public double d;
        public int f;
    }

    // during some changes in code then we got D2 from D1
    // Field f type became double while it was int before
    public struct D2 
    {
        public double d;
        public double f;
    }

    static void Main(string[] args)
    {
        // Scenario with the first version
        D1 a = new D1();
        D1 b = new D1();
        a.f = b.f = 1; …
Run Code Online (Sandbox Code Playgroud)

.net c# floating-point

247
推荐指数
8
解决办法
2万
查看次数

为什么return和throws语句的顺序会导致有关无法访问代码的不同警告

private static ext.clsPassageiro ConversaoPassageiro(ncl.clsPassageiro clsPassageiro)
{
     ext.clsPassageiro _result = new ext.clsPassageiro();
     throw new NotImplementedException();
     return _result;
}
Run Code Online (Sandbox Code Playgroud)

显示"检测到无法访问的代码" return _result;,

private static ext.clsPassageiro ConversaoPassageiro(ncl.clsPassageiro clsPassageiro)
{
    ext.clsPassageiro _result = new ext.clsPassageiro();
    return _result;
    throw new NotImplementedException();
}
Run Code Online (Sandbox Code Playgroud)

没有显示"检测到无法访问的代码" throw new NotImplementedException();,

为什么第二种情况没有显示警告?

.net c#

12
推荐指数
0
解决办法
117
查看次数

为什么必须在catch块中的throw语句之前返回语句

下面的代码会抱怨

try
{
    session.Save(obj);
    return true;
}
catch (Exception e)
{
    throw e;
    return false;  // this will be flagged as unreachable code
}
Run Code Online (Sandbox Code Playgroud)

而这不会:

try
{
    session.Save(obj);
    return true;
}
catch (Exception e)
{
    return false;
    throw e;
}
Run Code Online (Sandbox Code Playgroud)

我不明白......我以为我的csc101告诉我,return语句应该始终是函数中的最后一个语句,它退出函数并将控制权返回给调用代码.为什么这会违背我教授的逻辑,为什么只有其中一个产生警告呢?

c# computer-science

10
推荐指数
2
解决办法
6126
查看次数

VS.NET 2010对C#常量表达式的评估

当我在Visual Studio中尝试使用C#中的示例表达式时

public int Test()
{
    if (10/2 == 5)
        throw new Exception();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我保持表达式10/2 == 5时,vs.net会自动发出警告"检测到无法访问的代码".

如果我改变表达式10/2 == 6,IDE很高兴吗?怎么会发生?

编辑:对不完整的问题抱歉.即使在编译代码之前,它也会立即发生并发生?

我已经对每个回复进行了投票,并接受了基于FIFO的第一个答案

c# visual-studio

5
推荐指数
2
解决办法
282
查看次数