[.net] If you could request one feature for the next C# and/or .NET version, ...?

Started by
74 comments, last by Rainweaver 13 years, 8 months ago
Quote:Original post by ChaosEngine
Quote:Original post by itachi...


That relieves one use case of backing fields (granted if you're writing WPF/Silverlight, it's probably a large use case), but it doesn't alleviate the need for them completely.

What if you want to validate the value, for instance?


You're right, I was thinking (at least after I posted) of a more feature rich attribute that would also allow to specify custom Changing/Changed/Validate methods. Or maybe the compiler could just automatically look for methods inside that class that match a certain name and signature, so that if you have

[NotifyPropertyChanged]
public bool Blah { get; private set; }

the compiler would look for methods that match void OnBlahChanging(bool oldValue, bool newValue) and such... That, for me, would eliminate the need for backing fields in 99% of all cases. It would also be nice if it were possible to initialize the property to a certain value in that same line, something like: string Blah { get; set; } = "Hello";
Advertisement
There was also mention of readonly properties*

i.e.
class Something{    public readonly string Identifier { get; set; }}


The idea is that this allows construction of the object as follows:
var thing = new Something(){    Identifier = "the thing"};

but
thing.Identifier = "changed";
is an error.

It's basically a syntactic shortcut for
class Something{    private readonly string _identifier;     public string Identifier { get { return _identifier; } }    public Something(string identifier = null)    {        this._identifier = identifier;    }}



* for some reason I was convinced these were part of C# 4. Dunno where I got that idea.
if you think programming is like sex, you probably haven't done much of either.-------------- - capn_midnight
1:
Operators as part of interfaces, or demands that operators be defined as part of a generic type constraint. Constructors as part of interfaces, or demands that a non-empty constructor be defined as part of a generic type constraint.

2:
Either

Allow for an interface implementation to be satisfied implicitly if it is marked as an 'implicit' interface type [if it has all the methods for a given interface, it can be treated as being of that type].

Or

Allow for existing types to implement new interfaces in a fashion similar to how extension methods can be added to existing types.

Honestly, there is a lot with regard to generics that can really use some tweaking.
Yeah. Several people have proposed solutions, but any of the things that would enable generics on the built-in arithmetic types would be a big win. Of course, given the approach that many people here take to design, that's going to mean creating a new INumber interface, which will then be implemented by int/float/etc... Sigh.
Quote:Original post by ChaosEngine
There was also mention of readonly properties*

Do you mean like this?
class Test{    // "Readonly" property, since setter is private    public int X { get; private set;  }    // Read/write property    public int Y { get; set; }}


This won't work though:
var x = new Test() { X = 5, Y = 10 };
Quote:Original post by SamLowry
Quote:Original post by ChaosEngine
There was also mention of readonly properties*

Do you mean like this?
class Test{    // "Readonly" property, since setter is private    public int X { get; private set;  }    // Read/write property    public int Y { get; set; }}


This won't work though:
var x = new Test() { X = 5, Y = 10 };


I guess he means readonly
Quote:Original post by phresnel
Quote:Original post by SamLowry
Quote:Original post by ChaosEngine
There was also mention of readonly properties*

Do you mean like this?
class Test{    // "Readonly" property, since setter is private    public int X { get; private set;  }    // Read/write property    public int Y { get; set; }}


This won't work though:
var x = new Test() { X = 5, Y = 10 };


I guess he means readonly


Yep. For the record Sam, I am aware of what you mean, but as phresnel pointed out that is not readonly.

readonly (in the .Net sense) implies "set once, then frozen"
if you think programming is like sex, you probably haven't done much of either.-------------- - capn_midnight
This would mainly be a change to Visual Studio, not just C#.

I would love C# where curly braces are optional, and there were buttons to insert/remove them in all of the kinds of places they might be used. It would not cause problems for using other people's code because you could swap the braces to what you use. Of course a standard form of whitespace usage would have to be enforced, but I wouldn't mind that.

No curly braces is one of the things I really enjoy when I get to use Python.

I prefer all of the other things that C# has different from VB.NET. All except for curly braces.


But more importantly, I would like to be able to use future improvements of C# in Visual Stuido 2008! I don't like VS 2010 right now.
The ability to do the following (like C++)

public:    void Foo();    int Bar;private:    void FooBar();
Why can't you do that in C#?

This topic is closed to new replies.

Advertisement