Home c# error "for a non-static field, method or properties require reference to the...

error “for a non-static field, method or properties require reference to the object”

Author

Date

Category

Here is the simplified code of my program. Help sort out, newcomer. Thank you so much!

class program
  {
    Public struct dttable
    {
      Float Cash;
      int quancar1;
      DTTable Calc ()
      {
        DTTable MYTable = New Dttable ();
        int quancar1 = 0
            quancar1 = quancar1 + 10;
        }
        Return (MYTABLE);
      }
      Public Void SetDatatable (Dttable Indata)
      {
        Console.WriteLine ("Total: {0}", quancar1);
      }
      Static Void Main (String [] Args)
      {
        SETDATATABLE (CALC ()); // Error here
      }
    }
  }

Answer 1, Authority 100%

Make the setDatatable static method (write at the beginning of the STATIC modifier) ​​- and you will be happy.

Judging by the question, you do not understand what an object is, reference type and static class member.
Read the basics.
You can see a small lesson or some other, but be sure to deal with what is Object.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions