Member '' cannot be accessed with an instance reference

前端 未结 10 1683
我在风中等你
我在风中等你 2020-11-22 10:39

I am getting into C# and I am having this issue:

namespace MyDataLayer
{
    namespace Section1
    {
        public class MyClass
        {
            publ         


        
10条回答
  •  隐瞒了意图╮
    2020-11-22 11:19

    You can only access static members using the name of the type.

    Therefore, you need to either write,

    MyClass.MyItem.Property1
    

    Or (this is probably what you need to do) make Property1 an instance property by removing the static keyword from its definition.

    Static properties are shared between all instances of their class, so that they only have one value. The way it's defined now, there is no point in making any instances of your MyItem class.

提交回复
热议问题