Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

c# features - revised!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jarlaxle - 18 Mar 2008 16:20 GMT
alright...one more try at this...at least it got people talking about
it...This is just what I think would be good features...(which of course
doesn't mean jack)...but I think it's good to discuss...

1.  static extension methods

I think they would be very useful.  for instance adding other methods to the
RegKey class and/or the File class instead of having a ton of helper classes.
It also keeps related methods in one place.  it would also allow operator
extensions.

as Peter said the syntax would be an obstacle...

> How would you differentiate a "static" extension
> method from the instance extension method?  You could very well have a null
> value for an instance, in which case you couldn't use null.

I'm not sure why you couldn't define it like the following...

returnType MethodName(this typeName null, [...optional arguments])

so for instance...

DateTime Now(this DateTime null, TimeZoneInfo timeZone)
{
  //...return currrent time in the given timezone..
}

2.  return value by ref

I still think this adds a lot of value...especially in tight loops.  it
enables you to have structs as properties instead of direct access which
discourages encapsulation.

As Jon said...

> What would happen if you returned a local variable when "returning by
> ref"? The variable would have gone by the time the method completed.

This is a very common mistake for beginners in c++.  c# could issue a
compiler error..."local value variables can not be returned by reference."  
but is useful for static and/or member variables

just my opinion.

* Alright...I could do without auto created properties...I'll just have to
keep declaring the field and the get property body.

3.  Here is an idea I thought about last night watching tv (I guess I am a
dork)

(if this is hated by everyone...it does not reflect on the 2 above ideas!!!!)

extension methods that can override and/or block existing methods.  before
you start yelling...hear me out...imagine the possibilities!

you could enforce business protocols by using a standard library.  for
instance you could have a library that contains all your extension methods.  
in that library you could override the RegKey methods to write the values to
a file and then the registry.  no code would need to be changed and you could
persist data to a new location.

or you could override the DateTime (or block the local timezone methods) to
always return utc.  That would workaround all the DateTime issues.

I know I will get flamed but its a powerful idea.  The compiler replaces the
method calls to the overridden extensions.
Peter Ritchie [C# MVP] - 18 Mar 2008 16:32 GMT
> alright...one more try at this...at least it got people talking about
> it...This is just what I think would be good features...(which of course
[quoted text clipped - 6 lines]
>  It also keeps related methods in one place.  it would also allow operator
> extensions.

Keep your eye on http://blogs.msdn.com/charlie/ and
http://code.msdn.microsoft.com/vslangfutures

> 2.  return value by ref
>
> I still think this adds a lot of value...especially in tight loops.  it
> enables you to have structs as properties instead of direct access which
> discourages encapsulation.

If you want reference semantics instead of value semantics then don't use
structs.

> 3.  Here is an idea I thought about last night watching tv (I guess I am a
> dork)
[quoted text clipped - 3 lines]
> extension methods that can override and/or block existing methods.  before
> you start yelling...hear me out...imagine the possibilities!

No yelling, that would be a breaking change.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.