C# in Depth, Second Edition

Category: Programming
Author: Jon Skeet
4.6
All Stack Overflow 18
This Year Stack Overflow 3
This Month Stack Overflow 1

Comments

by anonymous   2017-08-20

Don't forget to read Microsoft .NET Framework 1.1 and 2.0 Compatibility.

After that, be sure to check .NET 4.0 migration issues document.

Read C# in Depth from Jon Skeet that describes all new features for each version of C#.

by anonymous   2017-08-20

Everything that BrokenGlass and pst have said is correct, but it seems there's still some confusion, stemming from the fact that these DevExpress methods return a List<object>, where object is:

An object which is an array of field values (if several field names are passed via the fieldNames parameter) or a direct field value (if a single field name is passed via the fieldNames parameter). (Source Link)

So, since you're passing multiple field names, code like this should work:

// Get the current values
var currentRowValues = m_ASPxGridView.GetCurrentPageRowValues("ID", "SID")
    // Cast each object to an array of objects
    .Cast<object[]>()
    // Project the two members of the array into an anonymous type
    .Select(x => new { ID = x[0].ToString(), SID = x[1].ToString() });
var selectedRowValues = m_ASPxGridView.GetSelectedFieldValues("ID", "SID")
    // Cast each object to an array of objects
    .Cast<object[]>()
    // Project the two members of the array into an anonymous type
    .Select(x => new { ID = x[0].ToString(), SID = x[1].ToString() });

// Compare the two collections to get the unselected row values
var unselected = currentRowValues.Except(selectedRowValues);

As we've been discussing, .NET won't know how to compare the two collections if they're of type object. However, it should work if they've been projected (using Select) to the same anonymous type -- I think by default it will use value-type equality.

Edit: According to Jon Skeet from C# in Depth:

Within any given assembly, the compiler treats two anonymous object initializers as the same type if there are the same number of properties, with the same names and types, and they appear in the same order.

...

Equality between two instances of the same anonymous type is determined in the natural manner, comparing each property value in turn using the property type's Equals method.

So, if I'm reading it right, the above code should do exactly what you're asking. Please let me know if I'm not ;-)

by anonymous   2017-08-20

Should i care about the previous versions?

Yes. You should at least know which features of 4.0 the older version DON'T have.

There's a good chance that if you're using .NET on the job, they're not going to be at 4.0 yet. Therefore, you're going to need to know which features you can use and which you're going to have to work around.

What are the tips you give for beginner to learn c# quickly?

Find a good book and start at the beginning.

I would recommend either Pro C# 2010 and the .NET 4.0 Platform or C# In Depth: Second Edition

What are the factors to be considered when moving from c,c++ to c#?

Know the naming conventions and differences of each.

C/C++ gets compiled to native code. C# gets JIT compilation.

C# has memory management. C/C++ doesn't (at least not the same).

C is not an object oriented langauge. C++/C# are, but each handles OO in a slightly different way.

Those kind of differences will change how you write/think about your code.

by anonymous   2017-08-20

C# 4 is basically a superset of all the other versions, so if you know C# 4 then you definitely know the earlier versions. On the other hand, I think it's worth knowing what's in which version. I have a couple of "bluffer's guides" on my C# in Depth web site which give a bit of information about C# 2 and 3 - I'll do a similar one for C# 4 soon. See this question for a very brief list of features in each version.

As for migrating from C and C++ - try to ignore everything you think you know. Some bits will be similar, some will be completely different. You should try to work the way the language expects you to, rather than applying C++ idioms to it.

You might want to read Essential C# 4.0, C# 4.0 in a Nutshell or Accelerated C# 2010. My own book - C# in Depth - will have a second edition soon, covering C# 4, but it's really designed for people who already know C# 1.

by anonymous   2017-08-20

Don't use Hashtables. Those have been obsolete for seven years, since .NET 2.0 came out. Use a generic collection, like a Dictionary, instead.

Dictionary<string, bool> myDict = new Dictionary<string, bool>();
myDict["foo"] = true;

bool myBool = myDict["foo"];

Generics are seriously wonderful. Do yourself a favor and spend a few hours looking into them. You might start here, with MSDN, and I really enjoyed Jon Skeet's book, C# in Depth, that covers the topic... in depth.