Sunday, July 3, 2011

Why I Love C# and Mono?

Let the comments in the code do the talking.
--------------------

using System;
using System.Collections.Generic;

public class Iter
{
    public class Book
    {
        //short way to declare a property:
        public string Title { get; set; }
        public string Author { get; set; }
    }

    public static void Main(string[] args)
    {
        // implicit type, yet still a strong type:
        var books = new List<Book>
        {
            // inline initialization:
            new Book { Title = "Book1", Author = "Moshe" },
            new Book { Title = "Book2", Author = "NotMoshe" }
        };
       
        // closure, lambda expression:
        books.ForEach(book => Console.WriteLine(book.Title));
    }
}

--------------------
Did you know C# has all of those cool features?
This is why I think that even if you're not going to write code in C#, you should get familiar with it.

2 comments:

  1. Wow Pascal in a Java Syntax :P

    ReplyDelete
  2. I love it too, I'm totally new to C# coming from a Ruby/Python Background, I just decided to merge into enterprise world :D, great comparison

    ReplyDelete