Question : c# Accessor Shortcut Question VS10

This is a really simple question, but I cant find the answer anywhere.

I'm using c# in VS10. I have a question about the following code:

    public int id { get; set; } // declare variable 'id' for class 'myClass'

Later, if I type _id (the generated pivate version of the variable), it is unrecognized by VS and treated as an undeclared variable.

So, if I use this method to create the public members, is there no way for VS to know that I will be using the private _id variable that will be created? Must I be explicit if I  need to use the private variables in code?

Thanks,

Answer : c# Accessor Shortcut Question VS10

public int id { get; set; } is automatic property and doesn't create any private version. Just use "id" in your code. http://msdn.microsoft.com/en-us/library/bb384054.aspx

If you still want access private use traditional style.

private int _id;
public int id
{
get { return _id; }
set { _id = value;}
}
Random Solutions  
 
programming4us programming4us