C# Automatic Properties

Bart has a report from Anders talk at TechEd on C# 3.0 Future Directions.  I'm hoping that the various talks from TechEd will be posted somewhere for us all to enjoy.  One of the new features Bart mentions... that Anders mentions...that I mention now....is Automatic Properties.  Up until this morning I had not heard of it as a feature, but apparently it's coming in a future release.  Like some of the other C# 3.0 features its sounds like it involves a bit of compiler magic!  Typing this:

public string Bar { get; set; }

Results in the compiler generating this:

private string foo;
public string Bar {
  get { return foo; }
  set { foo = value; }
}

Cool, eh?

 

Technorati tags: , ,

# re: C# Automatic Properties

Thursday, November 09, 2006 12:54 AM by Keith Hill    
I have asked for this for some time now. It would be very consistent with the compiler generated methods created as a result of using the event keyword. However I was hoping for a use model like the event keyword e.g.:

class Foo {
public property string Name;
public readonly property int Id;
...
}

# re: C# Automatic Properties

Thursday, November 09, 2006 9:01 PM by Steve    
I like your syntax better :) With the empty get; set; it feels too much like an interface. I'm sure whatever we end up with will become second nature within a couple days anyway. It's nice of them to include such features that save me from typing a couple extra of lines of code.

Post a Comment

 
 
Prove you're not a spammer: 
0 + 1 =