Java vs C# - Part 2
Introduction This is part two of a series of posts on Java and C#, the first part is available here . This time, I am going to talk about a lot of things that weren’t covered before, and leave some stuff for future posts! I'm covering: Object and collection initialization Casts Methods Operator overloading Attributes/annotations Exceptions Iterations Returning enumerables Lambda functions Expression trees Auto closing blocks Object and Collection Initialization C# offers an interesting syntax for initializing instance properties at the same time a variable is declared, which can be combined with parameterized constructors: MyClass c = new MyClass( "constructor argument" ){ OneProperty = 1, AnotherProperty = "two" }; It also offers a syntax for defining the values of a collection upon declaration, including dictionaries (indexed collections): var list1 = new List< string > { "A" , "B" , "C" }; List< string > list2 = [...