Originally Posted by
tinny
Object initializers:
Person p = new Person { Name="tinny" };
You can do something very similar in Java.
PHP Code:
Person p = new Person() {{
this.name = "tinny";
this.age = 19;
}};
Means that this also can be done:
PHP Code:
List list = new ArrayList() {{
this.add("first");
this.add("second");
}};
It's a hack but...
Things supernice in C# are delegates and anonymous delegates (example from wikipedia):
PHP Code:
public void Foo(object parameter) {
// ...
ThreadPool.QueueUserWorkItem(delegate
{
// anonymous delegates have full access to local variables of the enclosing method
if (parameter == ...)
{
// ...
}
// ...
});
}
extesion methods (example from wikipedia):
PHP Code:
public static class IntExtensions
{
public static void PrintPlusOne(this int x) { Console.WriteLine(x + 1); }
}
int foo = 0;
foo.PrintPlusOne();
python like iterators, generators(example from wikipedia):
PHP Code:
public static IEnumerable<int> GetEven(IEnumerable<int> numbers)
{
foreach (int i in numbers)
{
if (i % 2 == 0) yield return i;
}
}
and generics without erasure.
Edit:
Oh.. and I forgot one very nice thing - operator overloading!
Bookmarks