|
Architect or Cobbler?
Good code starts with good design |
|
about me
links
Blogs I follow
recent posts
archives
feeds |
New C# FeaturesThursday, September 15, 2005
Using type inference the compiler can infer the types. It should come as no surprise that these implicit types must always be initialised when used. So var x would cause a compiler error.
Extension methods are static methods which can be used to extend the functionality of a class without having to subclass the class, to declare and use this extension looks something like this:
Lambda expressions are introduced into the language to allow you to write anonymous methods. I know many of you might not even have got to grips with writing anonymous methods yet, but it does seem like a nice way of writing a piece of inline code. A lambda expression should be familiar to the Lisp programmers among you (or Scheme, or Haskell or any of the other functional languages), it is essentially an anonymous function where values can be bound to the function arguments at run time (or compile time in some languages, I was going to ask, but bottled it)
would run a query and return all those jobs that had a description "C# Debug" and priority less than 4.
You can also, although I was getting lost by this time (so I know what my homework is), use the lambda expression to build expression trees.
C# also includes the notion of initialisers now, so I could write a class and construct it like this:
If you read my last blog you would have seen me use an anonymous class in Visual Basic and probably wondered what it was. Well C# has the same facility, I simply provide initialisers to the constructor and an anonymous class with appropriate properties will be created. There is a naming scheme for these classes but I couldn't keep up.
So quite a few new features to be mulling over. It's a long time till C#3.0 is released, so the final release may look nothing like this, although that's unlikely the team appear to be quite a long way along this road, having released pre-beta implementations that actually do this stuff.
My head hurts now, but only one session left, and then I can go play on some rides.# posted by James @ 12:23 AM This looks like javascript to me :-) # posted by @ 9:45 PM It does doesn't it :-) There are some safeguards though. Once the variable has been 'set', then that type is bound to the variable, so type safety is still preserved. # posted by James @ 9:50 AM oh i can still see myslef getting caught out between var x = 1; var x = 1.0; var x = 1.0f; var x = 1.0d; :-) # posted by @ 7:27 PM Post a Comment << Main blog page |
|
|
|