Click here to Skip to main content
15,896,278 members
Home / Discussions / C#
   

C#

 
AnswerRe: Microsoft Office dictioanries Pin
Abhinav S1-May-10 6:08
Abhinav S1-May-10 6:08 
QuestionInteroperability Pin
Chiman11-May-10 1:55
Chiman11-May-10 1:55 
AnswerRe: Interoperability Pin
ThatsAlok2-May-10 20:20
ThatsAlok2-May-10 20:20 
Questionhow to change a value over a set period of time Pin
kennyhibs30-Apr-10 22:23
kennyhibs30-Apr-10 22:23 
AnswerRe: how to change a value over a set period of time Pin
OriginalGriff30-Apr-10 22:30
mveOriginalGriff30-Apr-10 22:30 
AnswerRe: how to change a value over a set period of time Pin
Luc Pattyn1-May-10 4:04
sitebuilderLuc Pattyn1-May-10 4:04 
QuestionMessage Removed Pin
30-Apr-10 21:59
mrkeivan30-Apr-10 21:59 
AnswerRe: An object reference is required for the non-static field, method, or property !? :( Pin
OriginalGriff30-Apr-10 22:26
mveOriginalGriff30-Apr-10 22:26 
The problem is quite simple, but you need to do some thinking (and possibly studying) because it shows that you have not understood static versus instance data.

public string _variable = String.Empty;

Declares a string variable called _variable, and assigns it to empty. Because this has no prefix, this is an instance variable. I.e. it is part of your class, and each instance of the calls has a separate copy of the variable. If this were cars, it could be the Colour - your car has a different Colour from my car.

public static string Variable
   {
   set { _variable = value; }
   get { return _variable; }
   }

Declares a string property called Variable. Because this has the static prefix, this is a static variable. I.e. it is part of your class, but all instances of your class share the same value. If this were cars, it could be CountTheWheels - your car and my car always have the same number of wheels - four.

Because the property is static, and the variable it is trying to use is instance, the compiler is telling you that you need to refer to a specific instance of your class in order to access the _variable value you want. What you are trying to ask is "What colour is any car?" - which is plainly nonsense since all cars do not have the same colour.

BTW: Do not make the _variable field public - that is what the property is for. If you expose the property and the backing field, which one is the user supposed to work with? The field? The property? Both? What if the property does something with the data before assigning it to the field - like validation?
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace

C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

GeneralRe: An object reference is required for the non-static field, method, or property !? :( Pin
Abhinav S30-Apr-10 22:50
Abhinav S30-Apr-10 22:50 
GeneralRe: An object reference is required for the non-static field, method, or property !? :( Pin
Luc Pattyn1-May-10 3:11
sitebuilderLuc Pattyn1-May-10 3:11 
GeneralRe: An object reference is required for the non-static field, method, or property !? :( Pin
OriginalGriff1-May-10 3:46
mveOriginalGriff1-May-10 3:46 
GeneralRe: An object reference is required for the non-static field, method, or property !? :( Pin
Luc Pattyn1-May-10 3:55
sitebuilderLuc Pattyn1-May-10 3:55 
GeneralMessage Removed Pin
1-May-10 3:58
harold aptroot1-May-10 3:58 
GeneralMessage Removed Pin
1-May-10 4:03
mveOriginalGriff1-May-10 4:03 
GeneralRe: An object reference is required for the non-static field, method, or property !? :( Pin
Luc Pattyn1-May-10 4:16
sitebuilderLuc Pattyn1-May-10 4:16 
GeneralRe: An object reference is required for the non-static field, method, or property !? :( Pin
OriginalGriff1-May-10 5:32
mveOriginalGriff1-May-10 5:32 
GeneralMessage Removed Pin
harold aptroot1-May-10 5:33
harold aptroot1-May-10 5:33 
GeneralRe: An object reference is required for the non-static field, method, or property !? :( Pin
Luc Pattyn1-May-10 4:14
sitebuilderLuc Pattyn1-May-10 4:14 
GeneralMessage Removed Pin
1-May-10 4:46
harold aptroot1-May-10 4:46 
GeneralRe: An object reference is required for the non-static field, method, or property !? :( Pin
Luc Pattyn1-May-10 5:05
sitebuilderLuc Pattyn1-May-10 5:05 
GeneralMessage Removed Pin
Luc Pattyn1-May-10 5:23
sitebuilderLuc Pattyn1-May-10 5:23 
GeneralRe: An object reference is required for the non-static field, method, or property !? :( Pin
OriginalGriff1-May-10 5:34
mveOriginalGriff1-May-10 5:34 
GeneralRe: Interesting Pin
Luc Pattyn1-May-10 5:42
sitebuilderLuc Pattyn1-May-10 5:42 
QuestionAsynchronous downloading in C# [modified] Pin
Sunil G30-Apr-10 21:31
Sunil G30-Apr-10 21:31 
AnswerRe: Asynchronous downloading in C# Pin
Abhinav S30-Apr-10 21:57
Abhinav S30-Apr-10 21:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.