Error I get:Code:using System; namespace Testing { class Class1 { static string name = "Chris"; static int age = 19; public string person = "Protected"; string person2 = "Private"; static void Main(string[] args) { try { Console.Write(name + " is " + age + " years old." + "\n"); Console.Write(person + "\n"); Console.Write(person2); Console.ReadLine(); } catch (System.Exception e) { Console.Write("Error: " + e); } } } }
C:\development\C#\Testing\Class1.cs(14): An object reference is required for the nonstatic field, method, or property 'Testing.Class1.person'
I'm just trying to experiment with some things in C#. Do I have to make everything static in order to use it? How can I create an object to use?




Reply With Quote