Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Friday, September 19, 2014

Something I always forget

I just wanted to note it down :)

Access modifiers in C#

public : Access is not restricted.

protected : Access is limited to the containing class or types derived from the containing class.

Internal : Access is limited to the current assembly.
protected internal: Access is limited to the current assembly or types derived from the containing class.


private : Access is limited to the containing type.

Monday, September 15, 2014

Zip extension method introduced in C# 4.0


This is a combining operator which combines items from one collection with item from second that are in the same position in the collection. See the example.

 class Program
  {
    static void Main()
    {
      var firstCollection = new List<string> { "Nalani ""Kamal ""Waruna ""Amal ""Surani " };
      var secondCollection = new List<string> { "Jayasundara""Amarasinghe""Hewage""Jayasinghe""Hasanthika" };
 
      firstCollection
        .Zip(secondCollection, (a, b) => a + b)
        .ToList()
        .ForEach(i => Console.WriteLine(i));
 
      Console.ReadLine();
    }
  }