So below is my code (really part of my code but at the moment all other methods and stuff is commented out and i want to try this piece of code)... my problem is i get the error message
"Error CS0120 An object reference is required for the non-static field, method, or property 'Sodacrate.Run()"
it just doesn?t go to "Sodacrate.Run()" what am i doing wrong?
the swedish in the code is just menu selecting.
Here it is!
Please help me
"Error CS0120 An object reference is required for the non-static field, method, or property 'Sodacrate.Run()"
it just doesn?t go to "Sodacrate.Run()" what am i doing wrong?
the swedish in the code is just menu selecting.
Here it is!
using System; namespace sodacrate { //create a class for sodas and declairing what?s required for a soda. class Soda { private string brand; private double price; private string type; public Soda(string _brand, double _price, string _type) //constructor { brand = _brand; price = _price; type = _type; } } //Creates a class for sodacrate wich includes an array of 24 bottles class Sodacrate { private Soda[] bottles = new Soda[24]; public void Run() { Console.WriteLine("V?lkommen till din digitala l?skbacks organiserare!"); Console.WriteLine("Just nu inneh?ller din back 0 flaskor"); Console.WriteLine("F?r att l?gga till en l?sk i backen tryck (1)"); Console.WriteLine("F?r att se vad som finns i backen tryck (2)"); Console.WriteLine("F?r att se totalpriset f?r din nuvarande back tryck (3)"); Console.WriteLine("F?r att avsluta programmet tryck (4)"); Console.ReadLine(); int menyVal = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("TEST"); } public void add_soda() { Console.Write("Vad heter l?sken du vill l?gga till?:"); string brand = Console.ReadLine(); Console.Write("Vad kostar den?:"); double price = Convert.ToDouble(Console.ReadLine()); Console.Write("ange typ (tex l?tt?l/l?sk/vatten:"); string type = Console.ReadLine(); Soda soda = new Soda(brand, price, type); Console.WriteLine(soda); } } class Program { public static void Main(string[] args) { //Skapar ett objekt av klassen Sodacrate som heter sodacrate var sodacrate = new Sodacrate(); Sodacrate.Run(); Console.Write("Press any key to continue . . . "); Console.ReadLine(); Console.ReadKey(true); } } }
Please help me
Last edited by a moderator: