将项目从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'
是什么导致这个问题?是否可以通过编译器设置来修复它?
我正在与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
它会失败.
我的问题是: