new features in c# 3

D

DAXU

Hi,

I just read some blogs which listed new features of c# 3.0. They
listed things like Automatic Properties,Object Initializers etc.

But frankly I do not see big changes from c# 2. It is not like in c#
2, they finally give us generics. Compare c# 2 to c# 1.1, generics is
something huge.
But I read part of c# 3 specifications, I don't have this feeling yet.

Maybe I missed something? Whould some one point it out for me?

Many Thanks

Jerry
 
M

Marc Gravell

And you'd be right... to a point ;-p

The C# 3 changes are largely (on the surface) some minor compiler
conveniences - but good conveniences. Extension methods, for instance,
I've already used in a number of scenarios completely unrelated to
LINQ. Many of the features tie tightly to eachother - for instance,
anonymous types demand the "var" type inference. Lambdas (as
delegated) feel cleaner than the older syntax, but yes: *by itself* it
isn't a killer feature (although the facility to compiler to an
Expression rather than a delegate is /extremely/ powerful - but
obviously demands .NET 3.5 [which C# 3 itself doesn't]).

However, the features really come into their own when considered with
their relationship with LINQ (.NET 3.5). Almost everything in C# 3
relates to LINQ in some way, so it is hard to evaluate their use
without some mention of LINQ. I started typing an "in particular", but
to be honest so much of the changes tie to LINQ that it became
unnecessary. Maybe auto-properties don't tie to LINQ... but that's
about it...

Regardless of your thoughts of LINQ-to-SQL etc, LINQ surely represents
an extremely powerful and expressive step forward, which hopefully
will make it easier for code to indicate what it is trying to achieve,
rather than masses of step-by-step how to do it.

This again important if you want to use things like PFX (or Parallel
Extensions, whatever they are calling it now), which is important
given the migration towards multi-core computing - the compiler can't
do anything with overly-specific code, but if you express your intent
and let the framework worry about implementation (rather than having
to continually write lots of parallel plumbing, and making lots of
mistakes in the bargain) you are onto a winner.

If you are interested in more information about the C# 3 particulars
and their advantages [or just more info], rather than focusing on
the .NET 3.5 details [which are of course mentioned, but only to
explain the "what?" and "why?"], then I can recommend Jon Skeet's
forthcoming book - it is /heavily/ geared toward the language rather
than the framework.

http://www.manning.com/skeet/

Marc
 
M

Marc Gravell

One other comment; remember that there is no CLI/CLR update for C# 3,
so there aren't any huge new concepts like generics; everything fits
mainly as compiler tricks within the existing frameworks (CLR 2.0),
with some optional features (Expression compilation) drawing from
framework updates (.NET 3.5). But no IL changes.

The default LINQ providers obviously draw from .NET 3.5, but this is
not tied directly to the compiler; the extension methods etc just
happen to pick them up according to the langauge spec. You can write a
LINQ-to-objects implementation in .NET 2.0, for example.

Marc
 
J

Jon Skeet [C# MVP]

I just read some blogs which listed new features of c# 3.0. They
listed things like Automatic Properties,Object Initializers etc.

But frankly I do not see big changes from c# 2. It is not like in c#
2, they finally give us generics. Compare c# 2 to c# 1.1, generics is
something huge.
But I read part of c# 3 specifications, I don't have this feeling yet.

Maybe I missed something? Whould some one point it out for me?

As Marc pointed out, there are no CLR changes like generics and
nullable types in 2.0. However, I think that LINQ (and indeed lambda
expressions in general) will actually make *more* of a change to how
we code. Rather than being a refinement of existing style, C# 3
encourages you to think more functionally/declaratively.

It's up to you, of course - you can choose to use C# 3 as if nothing
had changed, but you'll be missing out :)

Of course, I second Marc's recommendation of my book, by the way ;)

Jon
 
A

Alun Harford

Hi,

I just read some blogs which listed new features of c# 3.0. They
listed things like Automatic Properties,Object Initializers etc.

But frankly I do not see big changes from c# 2. It is not like in c#
2, they finally give us generics. Compare c# 2 to c# 1.1, generics is
something huge.
But I read part of c# 3 specifications, I don't have this feeling yet.

Maybe I missed something? Whould some one point it out for me?

I think the change is huge - particularly lambda expressions.

If I'm writing C# 2 code for other developers to use, I'm not likely to
expose a method that takes a delegate to control some aspect of that
method (I'd do that internally, but methods I expose to other developers
would take an object implementing an interface which basically wraps the
delegate in a method).

In C# 3, I'd be quite happy to expose a method taking a Func because
people know to supply a lambda (and they don't need to know the details
about how it works).

That's a pretty big change - at least as much as generics.

Alun Harford
 
J

Jon Skeet [C# MVP]

In C# 3, I'd be quite happy to expose a method taking a Func because
people know to supply a lambda (and they don't need to know the details
about how it works).

I think there are some details they don't need to know about, and some
they do. The exact procedure of type inference is really complicated
now, for instance - and most of the time you really don't need to know
what the compiler's doing. Captured variables, on the other hand, can
radically affect how your program behaves, and if you start using them
without being aware of them you could have a real problem on your
hands.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Target .NET 2.0 using C# 3.0 2
C# 3.0 new language features 33
c# features 10
how to create a c#3.0 project? 1
what is new in c# 3? 11
Upcast of generics in C# 3.0 12
new features 8
c# and java diffs 2

Top