小编ram*_*l89的帖子

Roslyn无法编译代码

将项目从VS2013迁移到VS2015之后,项目不再构建.以下LINQ语句中发生编译错误:

static void Main(string[] args)
{
    decimal a, b;
    IEnumerable<dynamic> array = new string[] { "10", "20", "30" };
    var result = (from v in array
                  where decimal.TryParse(v, out a) && decimal.TryParse("15", out b) && a <= b // Error here
                  orderby decimal.Parse(v)
                  select v).ToArray();
}
Run Code Online (Sandbox Code Playgroud)

编译器返回错误:

错误CS0165使用未分配的局部变量'b'

是什么导致这个问题?是否可以通过编译器设置来修复它?

.net c# linq roslyn

95
推荐指数
4
解决办法
7084
查看次数

SELECT语句中的Linq静态方法

我正在与EF合作并有一些疑问.这是我的代码

IEnumerable<Customer> customers = from c in context.Customers 
    select new Customer
    {
        ID = c.ID,
        Name = c.Name,
        LastName = c.LastName,
        DepID = c.DepID,
        Editable = SomeStruct.Check(c.DepID)
    }

public struct SomeStruct
{
    public static bool Check(int depID)
    {
        //Here I have some logic
    }
}
Run Code Online (Sandbox Code Playgroud)

它工作正常.但是,如果我宣布SomeStruct因为class它会失败.

我的问题是:

  1. 为什么会这样?
  2. 使用静态函数是否强制查询执行?

c# linq-to-objects linq-to-entities entity-framework

6
推荐指数
2
解决办法
3540
查看次数