No parametized types in C#? - c#

Reading the Bruce Eckel book "Thinking in C#", to relearn C#, since I haven'y used it for many years but am likely to be needing it again soon.
I was surprised by this statement:
"In C++, the keyword that implements
parameterized types is “template.”
.NET currently has no parameterized
types since it is possible for it to
get by—however awkwardly—using the
singly rooted hierarchy. However,
there is no doubt that parameterized
types will be implemented in a future
version of the .NET Framework."
I think I remember reading somewhere that C# has generics - which are similar to C++ templates?
Am I wrong, or is the Eckel book simply too outdated (if so, is it worth still reading or is there a more up to date book online?)
[Edit]
Eeek, I'm glad I checked in here first. Looks like I'll have to throw that book away (written in 2002 I believe). Can anyone recommend any downloadable book that has the same depth of Eckels 'Thinking in ...' series?
There are a lot of C# books out there, but most of them are far too basic, or do not cover enough material. I was happy to find Eckel's book, since he covers C# in usual thorough style (from an introduction to OOP [which I don't need], through WinForm and Threading) - Unfortunately, it looks like its too old (Damn you MS for changing C# specs more times than I've had hot dinners!)
Can anyone recommend a good downloadable C# book that has a similar width/depth coverage?
[Edit 2]
Just seen this book:
http://www.free-ebooks-download.org/free-ebook/dotnet/CSharp/beginning-visual-csharp-2010.php
I'd like the opinion of this book from any professional C# developers out there ...

It's probably describing C# 1.0, which didn't have generics.
I would recommend finding a newer book that covers LINQ (introduced in C# 3) and dynamic (C# 4).

I would definitely get the most recent book that's relevant to the version of the .NET framework you're programming for. I started with an old book which didn't even cover automatic properties. Now one year later, I'm changing all of the previous code because it's so bloated and verbose.
Anyhow, C# does have generics, which as far as I can tell are the equivalent of C++ templates.

Generics are in C# since .NET 2.0, which came with Visual Studio 2005. The book is older than 5 years, you definetly need to get rid of it! :)

As others have noted, your book is out of date, or rather describes an out-of-date version of the framework.
It's interesting to note that the first language specification for C# published to ECMA for standardization included generics as a part of the language. C# 1.0 and 1.1, in not including generics, were not full implementations of the C# language. 1.0 and 1.1 should have been numbered 0.1 and 0.2 or some such, but Microsoft doesn't number things like that, as risk adverse people avoid doing real work with beta products.

Related

How did generics influence the design of C# and .NET?

This might be a broad question but this is something I am not really clear and very curious.
Often times for certain problems I hear the reasoning that it was because Generics was not available in .NET 1.0. That makes me think either of these 2 things:
Generics was not thought of before, so the developers came up with it after .NET 1.0 which could drastically affect design of C# and .NET but couldn't because of decisions already made (backwards compatibility).
Generics was always planned since the beginning, so the only problem that arise from not releasing it with .NET 1.0 was not being able to use it till 2.0. But other than this, no redundant features were introduced or wrong, irreversible decisions were committed.
I mostly assume #1, but is #2 is the actual case?
Generics have been around a long time and can be loosely compared to C++ templates, although the concept (and probably implementation in other languages) predates even that.
.Net 1.0 is the first cut of a platform so the plan was to ship something that works reasonably. Generics would have to have been on the "planned future" if any decent architect was on the team, but is something that could be added later. In fact, the paper on implementing generics for .NET came out a year before .Net Framework 1.0 RTM eventuated.
Timeline: (http://en.wikipedia.org/wiki/List_of_.NET_Framework_versions)
2002-03-05 .Net Framework version: 1.0.3705.0 released
~May, 2001 Don Syme's paper on "Design and implementation of generics for .NET"
Microsoft could have taken 10 years to build .Net Framework 4.0 (as version 1.0), but with so much code and so many features out at once, it would take 5 years to find all the bugs and usability issues if the project can even succeed.
So the answer to your question would be #2.
Don Syme primarily designed and implementated generics into C# and .Net.
Resources
Language features added to C# over time (C# is the showcase language for .Net features)
Design and implementation of generics for the .NET Common language runtime
Formalization of generics for the .NET common language runtime
Anders Hejlsberg, lead architect of C#
Anders Hejlsberg talks a bit about generics
Anders Hejlsberg is my hero - from Wikipedia - original author of Turbo Pascal, the chief architect of Delphi, later lead architect of C#
I'm almost sure that generics were envisioned from the start. Full well realizing that the job was going to be considerable. The project was headed by Don Syme (of F# fame), his first publication about the design was dated January 2001. The CLR is presented as a given, the paper documents additions to the MSIL, although at the time .NET 1.0 had not shipped yet. That took another year. All and all, it's probably fair to conclude that it took them close to 4 years to hammer this together into concrete shipping software.
Don Syme, the designer of F#, was partially responsible for .NET generics.
if you're interested in the history of c# if check out channel9 and this video in particular
they have done a number of interviews with Anders Hejlsberg about this kind of stuff

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

I got a book named "Pro C# 2005 and the .NET 2.0 Platform, Third Edition by Andrew Troelsen".
I am wondering 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.

Which C# 4.0 Book would you purchase, and why? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm currently looking at purchasing a few C# 4.0 books, namely:
Essential C# 4.0 by Mark Michaelis or C# 4.0 Unleashed by Bart De Smet.
I am aware that both books are yet to be released, but would you consider purchasing either of these books, or would you recommend another?
Thanks for your time.
Clarification:
I'm not a .NET Ninja, but I do have 8+ years experience with the framework & related languages. So I'm generally looking for in-depth books. I also train/instruct the rest of my organisation generally 6 - 12 months after each .NET release. Each of the developers I train has the same or more .net experience than myself.
Once again thank you all for your time.
Update:
Thank you everyone for your responses. I've decided to purchase both books along with Visual C# 2010 Recipes: A Problem-Solution Approach, as suggested by Waleed Al Balooshi.
I was the technical editor for Mark's book. I quite enjoyed it, it is well written, and accurate.
An interesting thing about the difference between Mark's book and Jon's book (for which I was also the technical editor) is that both of them have accurate titles. "C# in Depth" really does go into quite a lot of depth; Jon doesn't shy away from the abstruse or theoretical, though of course he always has an eye on the practical. Mark's book really is more about cutting to what is essential to understand in order to get the job done. Both approaches are valid and reasonable.
Bart is a smart guy and I would imagine his book is quite good; not having read it, I cannot offer a personal opinion one way or the other.
I would recommend that you buy the MEAP (Early Access Edition) of Jon Skeet's C# in Depth 2nd edition, which is updated to include C# 4.0
In addition to this there is also:
C# 4.0 in a Nutshell: The Definitive Reference (Already Out)
Other than that I can't really say about the other books, because they aren't out yet, but I like the A Problem-Solution Series:
Visual C# 2010 Recipes: A Problem-Solution Approach (Not Out Yet)
I would wait till the books are out and you can read some reviews about them, till then I again highly recommend Jon Skeet's book.
In full disclosure, I am an editor with Addison-Wesley/Pearson. C# books are not one size fits all. It depends on your level of experience, as well as your programming background (are you a Java developer wanting to learn C# or are you trying C# programming for the first time?). We are publishing a lot for the 4.0 release, which may seem like over publishing to an outsider, but consider these differences: Sams Teach Yourself Visual C# 2010 is a quick get “up-and-running” tutorial for the very beginner. No programming experience needed. Bill Wagner's Effective C# books are a healthy dose of hard-earned wisdom, advice, and tips for the intermediate to experienced C# developer. C# 4.0 How to is a “just-what-you-need-to-know” title that focuses on general explanations and teaching “essentials” to the working, intermediate-level developer. Mark Michaelis' popular "Essential C#" is a “start-to-finish” guide focused ONLY on the C# language (2.0, 3.0, and 4.0) for the beginner to intermediate developer while C# Unleashed is the comprehensive “everything but the kitchen sink” reference guide focused on C# and .NET for the intermediate developer. Finally the Deitel's publish a lot of textbook C# for the academic community. I will also vouch for Jon Skeet's C# books. He is very knowledgeable and well regarded in the community. Whatever you decide, I would recommend taking a look at sample chapters that publishers release to see what approach/author best meets your needs.
I would wait for Jon Skeet to write one and buy it.
+1 for Bart de Smet. You can sample his writing by visiting his blog, which has been in my aggregator for years.
In the end, however, the most important thing is to find someone whose approach resonates with you.
Pro C# 2010 and the .NET 4.0 Platform
This is probably the only book you will need.
I would wait until after April and look at blogs and podcasts until then to be absolutely sure things don't change too much!
This book looks quite good for newcomers:
Introducing .NET 4.0: With Visual Studio 2010
http://www.amazon.co.uk/Introducing-NET-4-0-Visual-Studio/dp/143022455X/ref=sr_1_1?ie=UTF8&s=books&qid=1265798479&sr=8-1
I'll probably hold out till
Pro C# 2010 And The .NET 4.0 Platform 5th Edition (Andrew Troelsen)
http://www.amazon.co.uk/gp/product/1430225491/ref=s9_simi_gw_p14_t1?pf_rd_m=A3P5ROKL5A1OLE&pf_rd_s=center-1&pf_rd_r=1B44BHPWP93JTH087A55&pf_rd_t=101&pf_rd_p=467198433&pf_rd_i=468294
The devil you know is better than the devil you don't: Mark Michaelis has published several books, mostly on C#, while de Smet seems to have only this title to his name. I'd go with Michaelis.
It depends on what you are looking for? Do you want a beginners book or a more in-depth book? It also depends on the style of book you are looking for. Another one, also not released yet, is the upcoming Sams Teach Yourself Visual Studio 2010 in 24 Hours< (which is really focused on C# 4.0 rather than Visual Studio).
It depends on what you need from the book.
If you want to push C# to newcomers, you might want to try O'Reilly's Programming C# 4.0 or Beginning C# 4.0 from Wrox.
If you're looking for a language drill-down, then you've already got C# in Depth on order, but I would consider Bart de Smet's book as well as another c# stunt coder, given his blog.
If you're looking for more real-world applications, I'd highly recommend Bill Wagner's Effective C# which is being updated for C# 4.0. This is one of the books that sits on my desk almost all the time. I really like it.
I would prefer book of Microsoft publication (MOC) , BLACK BOOK and wrox publication book
If you're looking for suggestions for one particular good C# book, I would recommend a couple different books of your choice at the same time. You always get a good cross-section of knowledge that way because different authors use different analogies, have different angles on teaching, etc. It makes you wiser.
Additionally, supplement your book knowledge with materials and samples from the Internet like MSDN, CodeProject, etc. Some books have companion CDs.

What are the differences between C#.net and Visual Basic.net?

I have a small experience in VB.net and I would like to learn C#.net
What are the differences between VB.net and C#.net?
Is there any difference in performance between these two?
Apart from the syntactical differences, are there any major changes that I have to keep in mind?
The Language Features section of the Wikipedia article offers a good overview. Performance is essentially equivalent in almost every aspect, from what I understand.
Performance is equivalent if you write equivalent code, but VB.NET has constructs that are in there for "backward compatibility" which should NEVER be used. C# doesn't have some of these things. I'm thinking specifically of:
Functions which are in the Microsoft.VisualBasic namespace which are members of other standard .NET classes like Trim(). The .NET classes are often faster.
Redim and Redim Preserve. Never to be used in .NET, but there they are in VB.
On Error ... instead of exceptions. Yuck!
Late binding (sometimes derisively called "Option Slow"). Not a good idea in a non-dynamic .NET language from a performance perspective.
VB is also missing things like automatic properties which makes it pretty undesirable for me. Not a performance issue, but worth keeping in mind.
I think you will find the answers to your question in this articles:
http://en.wikipedia.org/wiki/Comparison_of_C_sharp_and_Visual_Basic_.NET
and
Link
edit: Noldorin was faster :x
The first thing to know about learning C# is that it is not pronounced "C#.net", it is just C#. Microsoft tacked on ".NET" to VB, because there was a previous version of VB that didn't work on the .NET Framework. C# was created specifically with the .NET Framework in mind, so the ".net" is implied and unnecessary. Also as a side note putting "C#.NET" on your resume really tips off a knowledgeable manager to your skill level, or lack there of, regarding C#.
Also this Wikipedia article is really good for showing the pros and cons as well as the differences between C# and VB.NET at a high level.
Follow following links which give detailed differences
http://www.harding.edu/fmccown/vbnet_csharp_comparison.html
http://www.codeproject.com/KB/dotnet/vbnet_c__difference.aspx
http://support.microsoft.com/kb/308470
In spite of differences as mentioned at http://support.microsoft.com/kb/308470 both C# and VB.Net are first class citizens of .Net world
Although there are differences between
Visual Basic .NET and Visual C# .NET,
both are first-class programming
languages that are based on the
Microsoft .NET Framework, and they are
equally powerful. Visual Basic .NET is
a true object-oriented programming
language that includes new and
improved features such as inheritance,
polymorphism, interfaces, and
overloading. Both Visual Basic .NET
and Visual C# .NET use the common
language runtime. There are almost no
performance issues between Visual
Basic .NET and Visual C# .NET. Visual
C# .NET may have a few more "power"
features such as handling unmanaged
code, and Visual Basic .NET may be
skewed a little toward ease of use by
providing features such as late
binding. However, the differences
between Visual Basic .NET and Visual
C# .NET are very small compared to
what they were in earlier versions.
No matter which language you select based on your personal preference
and past experience, both languages are powerful developer tools and
first-class programming languages that share the common language
runtime in the .NET Framework.
Says by Microsoft
https://web.archive.org/web/20061027230435/http://support.microsoft.com/kb/308470

Equivalent of Bloch's Effective Java for C#

I've jumped into the C# bandwagon and was wondering if there's an equivalent of Joshua Bloch's Effective Java for the C# world.
I've already being able to apply some Java knowledge to C# given their similarity but I'm interested in knowledge to make the most effective use of C# specific features. For example, Generics are not implemented equally in Java and C#, so it's not clear to me if the Java Generic "techniques" will work in C# as well.
I'm mostly interested in C# 3.0. That is (of course) unless you guys think I would benefit for looking into versions 1 and 2 features.
Jon Skeet's C# In Depth is a favorite among StackOverflow users.
(source: askjonskeet.com)
There are two books Effective C# and More Effective C# by Bill Wagner that are similar to Effective Java.
Since you want something in the same line of Effective Java the following two books are very similar:
Effective C#
http://img253.imageshack.us/img253/8619/0321245660aa6.jpg
More Effective C#
http://images.amazon.com/images/P/0321485890.MZZZZZZZ.jpg
I found CLR Via C#, by Jeffery Richter, to be very good. It discusses the CLR and framework in some depth and gives you a greater understanding of how to use various feature along with potential pitfalls.
I think Framework Design Guidelines is the closest. While I don't think it's comparable to Effective Java in terms of depth, I haven't read found any better book in the same category.
C# in Depth is great, but it focuses more on the language than design issues in .NET. Therefore, I wouldn't put it in the same category with Effective Java.
How about Effective C#?
It's amazing to see how many people get to write books in the same vein as Scott Meyers' "Effective C++" and "More Effective C++". Here's an algorithm for becoming a published author:
Learn new language X.
Publish "Effective X" and "More Effective X".
Bank tsunami of currency that rolls in.
"Effective Haskell", anyone?
I don't mean this to denigrate anyone who does this. It's more of an homage to Scott Meyers - as good a computer scientist and writer as there is.
It is worth noting that a second edition of Bill Wagner's Effective C# was published recently (18th March 2010 in the UK). This second edition updates it to cover C# 4.0.
Personally, I was wholly unimpressed by the original edition of Effective C#, However, having bought this second edition a few days ago, it appears much better. It is not plagued by the same level of misprints, repetition and, most importantly, it correlates better with what I perceive as best practise rather than just detailing a lot of arbitrary personal choices.
The fact that it is updated to cover C# 4.0 is also important!
Having said all that, these are only my early observations as I haven't read much of it yet!
Effective C# and More Effective C# by Bill Wagner. The second book deals with C# 2 and 3.
Either here and here on Amazon.com
or here and here on Amazon.co.uk
There's a new version of Effective C# (Amazon UK) that covers C# 4.0.
Beaten to it by Andy, but I was looking up the links.
Jon Skeet's C# In Depth is also worth mentioning.

Categories

Resources