1

我有一个看起来像这样的私人课程:

private class PocoUserWithResourceId
{
    public USER User;
    public string ResourceId;
}

我用这个类做事(在同一个封装的公共类中),比如:

var uQuery = from u in db.USERS.All()
select new PocoUserWithResourceId {User = u, ResourceId = arv.Resource_Id};

我收到警告:

字段“PocoUserWithResourceId.ResourceId”从未分配给,并且始终具有其默认值 null

我错过了什么?我在我的 LINQ to SQL 代码中分配值。

4

2 回答 2

4

Is it just because I'm assigning property values during the declaration that the compiler doesn't see the fact that I'm using them?

No, that's just because you're assigning field values, not property values ...

You have choice between 2 good practices :
- Use a constructor
- Use accessors (properties)

于 2012-10-30T09:02:46.317 回答
0

您可以使用 #pragma 暂时禁用特定情况的警告

// turn it off
#pragma warning disable 0649
private class Foo
{
   public string FieldName
}
// turn it back on
#pragma warning restore 0649

要找出错误号,请检查原始输出或右键单击警告并选择显示错误帮助。即使页面本身与警告无关,您也会发现隐藏在 URL (CS0649) 中的错误。

于 2015-12-16T18:56:04.363 回答