I am working on my first C# program and have run into a brick wall. I want to be able to set and get variables throughout diferent forms in the same application.
I created a class called “data” which contains the following:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Application1
{
public class data
{
public string SearchAirport
{
get
{
return searchairport;
}
set
{
searchairport = value;
}
}
}
}
What do I need to put into my forms to be able to use this class??
Right now all I have is:
data.SearchAirport = commandAirport;
string working = data.SearchAirport;
I know I have to add something else to keep from getting the:
“Error 11 An object reference is required for the non-static field, method, or property ‘Sector_Datastore_2._0.data.SearchAirport.get’…”
error
You are accessing searchAirport statically, and the method itself is not static.
You can either add the
statickeyword to theSearchAirportmethod signature or create adataobject and then callSearchAirporton that object.