|
I completely agree on the syntax - that's why I use the methods instead - but Linq does have some advantages over the "loads of loops" approach!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Agreed! Linq makes things easier to write, easier to maintain, easier to understand, and just makes code 'prettier'. I cannot stand ugly code!
|
|
|
|
|
Does linq make the code more readable to the next programmer who picks up your code? If the linq covers a simple loop with some decisions inside which will be easier for the next person who maintains the code? Writing code for an organization with multiple programmers and engineers, not only must your code perform what is intended without breaking, but must be as quickly understandable by the next person who pick up the code. Because, you can be sure that your code will change as the customer needs change.
|
|
|
|
|
I agree with using a var for what clearly should be an int. Or should it be a long? Or a 64-bit unsigned int?
As for your 'p' example--it all depends on what you do with it next. If you just need to hang on to it so you can eventually return it from the current function, or to pass it as a param to another function, then under those circumstances I'd say the exact type shouldn't matter to a reader.
|
|
|
|
|
The first example is OK. I as a maintaining programmer know that i will be an int of some sort. The second example, what is p? Do I have to look at the function or intellisense to figure it out? Do I need to look at the context of how p is used later? No to all of these. The professional engineer's job is to not only make the product work as expected but to also make it easier for the next engineer to pick up the work and take it to the next step. (It's in the IEEE code of ethics.) It would seem that is the difference between a programmer/code jockey and an engineer.
|
|
|
|
|
OriginalGriff wrote: C# needs to be ripped apart and the same exercise done again
Couldn't agree more. It's getting so bloated and ugly that it's starting to look like C++.
To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson
Our heads are round so our thoughts can change direction - Francis Picabia
|
|
|
|
|
Actually, they simplified C++, as did Java. C++ was getting quite complicated and watching Bjarne Stroustrup running through the variations of template examples was enough to make your head swim. Both Java and C# are good attempts to simplify what C++ has become. Also, most people decided to take up C# because of the pointer problems with C++. Too many times, a raw pointer would be missed or deleted too soon and problems would arise. This was occurring in much larger programs. So, I am happy (so far) with C#.
|
|
|
|
|
I'd also agree on "C# in a Nutshell" by Joseph and Ben Albahari. If you ever really want to take a deep dive into C# and the CLR I highly recommend "CLR via C#" by Jeffrey Richter. In the meantime though, the Microsoft Docs on C#[^] are quite good to start off with
|
|
|
|
|
Jon McKee wrote: "CLR via C#"
This book is awesome. Must read for an in depth understanding of C# on top of .net.
To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson
Our heads are round so our thoughts can change direction - Francis Picabia
|
|
|
|
|
This is the best choice, especially if you're coming from native c++. You need to learn not just the c# language, but how to use it effectively on the .net platform. I also came from c++ to c# via this book.
|
|
|
|
|
Always read the spec. Anything else is wrong.
|
|
|
|
|
So you are wrong
|
|
|
|
|
|
|
Programming in the key of C# by Charles Petzold is excellent, especially when coming from older C-family languages
|
|
|
|
|
I know this is not exactly an answer to your question, but I would warmly recommend the following:
1) Job interview questions as by far the best source of condensed information about very handy C# features. A 100 questions interview is worth 314 pages in a book.
2) F..k Occam's razor. Complicate! Go to Stack Exchange and check three solutions to your problem, even if you know how to solve it. It helps build your skills beyond trivial.
3) Twitter for practicing code optimization.
|
|
|
|
|
If you want something that starts at the core of C# and - to a degree - programming, I'll have to recommend Rob Miles' Yellow Book[^]. It certainly helped me learn C# quite thoroughly, although I'll have to admit that he was one of my lecturers when I attended university.
|
|
|
|
|
|
Hi,
I have had good luck with the "Dummies" books. I needed to learn C++ in two days and the "Dummies" book was right on target. I also got a lot of value from the Python "Dummies" book. Try C# for Dummies.
|
|
|
|
|
It depends what you mean by 'from 0'. If you have C++ experience it may not be necessary to start right from the bottom. The most interesting one I have read, though a little advanced, is Accelerated C# 2010 by Trey Nash. That said, I rarely use C# these days as i have jumped ship to Java and JavaScript / PHP, so I may not be the best person to ask! The hardest part of C# to learn, in my experience, is delegates and the above book explains these well. In fact i never understood delegates at all until I read Trey's book. personally, though, I prefer the way Java handles events, I find this more intuitive.
|
|
|
|
|
CLR via c#[^]
Especially if you're coming from native c++, you're looking to learn not just the c# language, but how to effectively use it on the .net platform.
|
|
|
|
|
Hi! I think the best book is
LINK[^]
|
|
|
|
|
I've had good luck with the SAMS books. Each is a series of lessons that typically take an hour to do, although anyone with programming experience will zip through the first third of the book. For people that learn best by doing (like me), the lessons with examples and programming assignments works well. A lot of the books include a CD/DVD, and programming examples are available for download.
The current book is SAMS Teach Yourself C# in 21 Days[^].
Note: I have not personally used this book, although I've had good luck with a number of SAMS titles in various areas. If I was learning C# now, it's the first book I'd buy. I do have WROX Professional C# 2008 (which tells you when I learned C#). That kind of book is an excellent reference, valuable to own, but not (IMO) a good learning tool.
I spotted another book on Amazon, this one is supposed to be a platform independent book on C#: SAMS Teach Yourself the C# Language in 21 Days[^].
Although I haven't seen it discussed, I tend to buy in ebook format, as it's easier to cart the books around. I open books on a tablet and have that standing next to the monitor when learning something new, and even better when using a book as a reference. However, I prefer hard copy for learning, but space and weight considerations have pushed me to ebooks.
|
|
|
|
|
I was going to make an elements pun, but ... all the good ones Argon.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Fe E's sake, U must Ti harder!
... such stuff as dreams are made on
|
|
|
|