开发者

C# - What will I miss if I start with .NET 2.0?

开发者 https://www.devze.com 2023-01-16 05:32 出处:网络
I got a book named \"Pro C# 2005 and the .NET 2.0 Platform, Third Edition by Andrew Troelsen\". I am wondering 开发者_Go百科whether I should buy the \"Pro C# 2010 and the .NET 4 Platform, Fifth Editio

I got a book named "Pro C# 2005 and the .NET 2.0 Platform, Third Edition by Andrew Troelsen". I am wondering 开发者_Go百科whether I should buy the "Pro C# 2010 and the .NET 4 Platform, Fifth Edition" instead. Since, the latest version of .NET is 4.0. If I learn C# based on this old book, do I miss some critical parts of the C# language? Or, I can start with this book and learn new .NET 4.0 features with other resources.

Thank you


You can start with that book and learn C# 4.0 from elsewhere. This is what's been added after C# 2.0:

C# 3.0:

  • LINQ
  • lambdas
  • extension methods
  • expression trees
  • anonymous types
  • local type inferencing
  • automatic properties
  • object initializers
  • collection initializers
  • partial methods

C# 4.0

  • dynamic member lookup
  • covariant and contravariant generic type parameters
  • optional parameters and named arguments
  • parallelization framework (actually part of .NET 4, not C# 4.0 per se)


You will miss a lot. Most notably in my opinion, Linq. Linq changes the whole face of idiomatic C# so much that I could not reccommend starting with the old book.


I think you will be missing out on LINQ, which is quite a notable addition. If you are open to other reccomendations, I would say try Jon Skeet's C# In Depth. It gives a very good coverage of the various changes in the language from versions 2.0 to 4.0 (I purchased the early access edition).


Lambdas / LINQ are pretty huge.


C# 2 has generics, and it's good, but C# 3 and 4 have LINQ and dynamic typing, respectively, both of which are very powerful in their respective milieus.

And that's just to name two. There's a crap-ton more in there that you're missing out on.

If you can, always develop against the latest version.


You can certainly start with C# 2.0 and learn the basics. There are many great new features in C# 4.0, but many of them are advanced or what are called 'syntactic sugar' meaning it's a more terse way of writing something you could already do with C# 2.0.

There are many different posts about the new features you can reference, without buying a complete book on it:

http://www.15seconds.com/issue/080228.htm http://code.msdn.microsoft.com/cs2010samples

I'd reccommend not spending the money up front, and checking out what the interweb has to offer.


Personally, I think 2.0 is the right version of C# to start with. If you're going to learn the language for the first time, then starting with 2.0 is totally fine. 2.0 is the major release of the core language.

From 3.0 some features have been added which are nothing but "syntactic sugars" and "time/typing savers", and which confuse beginners, and you're gonna have to post questions here like "whether I should use constructors or object initializers".

Of course, you'll not find the new features added in 3.0 and 4.0 in a book for 2.0. But just as you said, you can always be introduced with those from other resources.


I wouldn't recommend you start learning C# with such an old version.

If you have the money to buy the new edition you should go for it. There were a lot of changes since .net 2.0.

If buying a new book it's not possible for you at this moment you could start learning the basic stuff from that book and learn new features from online resources.


You would miss most of the new technologies. 3.0 introduced WPF, WCF and WF 3.5 gave us LINQ, and other related techniques like lambda expressions, extension methods... 4.0 brought the DLR, for dynamic typing.

A full summary of new features can be found on wikipedia.


LINQ isn't all you'll miss. A lot of technologies that were added to 3.0 with LINQ (and largely because of it) stand on their own merits and make it very worthwhile to adopt the latest version.

  • Lambdas
  • Anonymous Methods (might have been 2.0, can't remember at the moment)
  • Type Inference
  • Dynamic types in 4.0
  • Lots of new classes and improvements

I think you might be doing yourself a disservice if you cripple yourself with 2.0 if you don't really have to. The Framework is, after all, free, and so is the online documentation. Further, online tutorials abound, and you hve a plentiful resource for programming advice right here on StackOverflow.


MSDN has a helpful set of pages (start here) that tell you exactly what you will be missing out on when you target older versions of C# and the .Net Framework.

Remember when you target a C# version you are not just tying yourself to the language but to the matching .Net Framework - there is a whole bunch of new stuff in 2008 and then again in 2010 that you will miss out on by going .Net 2.0.


The major things you will want to know about that have come along since 2.0 include:

  • Linq (a powerful compiler-checked query language used for list/set processing and as an interface to ORM frameworks).
  • Anonymous types and delegates (lambda expressions). Need to store a list of some data fields you've gotten from a Linq expression, but don't need/want to define a whole new type just to store them? You don't have to anymore. Similarly, if you need to do something to each element of a list, or specify some operation to return a result, but don't want to define a named method, you don't have to. C# allows you to specify "anonymous" types and delegates, which are defined where they are used and are accessible only through the variable containing the delegate or data reference.
  • WPF (The next generation of UI development, it is an XML-based presentation layout definition that will EVENTUALLY replace WinForms and ASP.NET)
  • WCF - the next generation of web service classes, supporting built-in security features like encryption.
  • Microsoft Entity Framework - Microsoft's take on ORM frameworks like NHibernate
  • Dynamic typing - C# 4.0 allows for relaxed type restrictions by defining types or parameters as dynamic. This allows .NET to interface more seamlessly with assemblies or native APIs written in "duck-typed" languages (where the type is always dynamic, inferred from what you're trying to do with the instance)
  • Better covariance/contravariance support - .NET 4.0 allows you to specify that collections of a type can be treated as if they were a collection of a derived type, or an ancestor type.


The versions of .Net are all primarily similar, but the only thing you may glean by starting with 2.0 would be to get a history of where certain changes in the languages came from. That's more of an experience thing though. If you're not already trained in C#, it would be best to start at the very latest. The fundamentals of the language will still be the same. You'll also learn the latest techniques for accomplishing common tasks rather than learning an outdated method and then having to relearn it later and try to understand the differences and why it exists in the first place.

Start with the latest stuff. Don't learn from antiquated sources and then try to fill in the gaps with extraneous information.


Programming technologies change so fast as it is, why would you invest time reading such an old book? I'd get the newest one.


As well as the aforementioned Linq/lambdas etc, the later books will also cover technologies such as WPF which has pretty much replaced winforms for desktop development, and WCF which is the common communications method now, so I'd try and get a later book.

0

精彩评论

暂无评论...
验证码 换一张
取 消