Wriju's BLOG

.NET, Cloud and everything

C# 3.0 is 100% backward compatible with C# 2.0

It’s a statement that C# 3.0 supports each and everything of C# 2.0. It was required to maintain the C# standard. But lot of ground work has been done in terms of bringing the level of abstraction and set of new keywords in C#. Now the question is if you have set of new keywords which were not there in C# 2.0, how the old code will get compiled? What will happen if someone has used them as variable in their code? Yes, it works. The same keyword works as variable name as well as keyword compiling itself as first class native statement. Below is the classic example I demonstrate in my demos, (believe me this code compiles in Orcas Beta 1)


 


using System;


using System.Collections.Generic;


using System.Linq;


using System.Text;


 


namespace CSharp3Demo


{


    class Program


    {


        static void Main(string[] args)


        {


            //Array of integers


            int[] arrInt =


                new int[] { 1,2,3,4,5,6,7,8,9,10 };


 


            //Use of the variable names using the keywords


            //”from”, “where”, “select”


            string from = “This is the kw from”;


            string where = “This is the kw where”;


            string select = “This is the kw select”;


 


            //print the “from” variable


            Console.WriteLine(from);


            //print the “where” variable


            Console.WriteLine(where);


            //print the “select” variable


            Console.WriteLine(select);


 


            //Query Expression


            //To find the even numbers


            //Use of the keyword “from”, “where”, “select”


            IEnumerable<int> evens = from evenInt in arrInt


                        where evenInt % 2 == 0


                        select evenInt;


 


            foreach (int i in evens)


            {


                Console.WriteLine(i);


            }           


        }


    }


}


 


Comment if you have any query. Let us know if anything which was working with C# 2.0 but not in C# 3.0. We value your feedback.


 


Namoskar!!!