Member '' cannot be accessed with an instance reference

前端 未结 10 1940
我在风中等你
我在风中等你 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:06

    I had the same issue - although a few years later, some may find a few pointers helpful:

    Do not use ‘static’ gratuitously!

    Understand what ‘static’ implies in terms of both run-time and compile time semantics (behavior) and syntax.

    • A static entity will be automatically constructed some time before
      its first use.

    • A static entity has one storage location allocated, and that is
      shared by all who access that entity.

    • A static entity can only be accessed through its type name, not
      through an instance of that type.

    • A static method does not have an implicit ‘this’ argument, as does an instance method. (And therefore a static method has less execution
      overhead – one reason to use them.)

    • Think about thread safety when using static entities.

    Some details on static in MSDN:

    • Static Classes in C#
    • Static Constructors in C#

提交回复
热议问题