If at first you don't succeed, call it version 1.0

Contact Me

Sarvesh Kushwaha
Email : sarveshkushwaha@outlook.com

Total Pageviews

Powered by Blogger.

Sunday 12 February 2017

10 Essentials C# keywords every .Net developer should know before attending an Interview #AspNetInterviewQuestionsSeries


1. Var and/vs Dynamic

With Var keyword properties / Methods /Operators etc are resolve at compile time.
Var keyword is static typed and type cannot be change,Once you have assigned the type to var.

var i = "abc";
i = 1 ; //you cannot assign it integer value once it has been marked as string


With Dynamic keyword properties / Methods /Operators etc are resolve at runtime.
type can be change once it is already assigned.

dynamic i = "abc";
i = 1 ; //you can change the type in dynamic
Console.WriteLine(i.anything); //error will be given at runtime

2. Const and ReadOnly
  1. Constants are evaluated at the compile-time, while the read-only variables are evaluated at the runtime. 
  2. Constants support only value-type variables, while read-only variables can hold reference type variables. 
  3. Constants should be used when the value is not changing during the runtime, and read-only variables are used mostly when their actual value is unknown before the runtime.

static readonly string readonlystring;   //you can levae it blank and can assign value at runtime,assign object to it 
 const string constring ="abc"; // you have to assign some value to const while declaring,you can assign ref type to const

3. Checked and Unchecked keyword
Checked keyword is to check integral arithmetic overflow.
What will happen if you are assigning the greater value to your int than its maximum value?
you will get the wrong result,to check above condition and throw airtmetic overflow use Checked keyword either in block () or in expression {} manner.



//checked block
int checkedk = int.MaxValue;
  Console.WriteLine(checked(checkedk+ 20));
  
  //checked expression
   checked
   {
    int i = 10;
     int i3 = 2147483647 + i;
                Console.WriteLine(i3);
   }

unchecked keyword is just opposite of that it will not throw any exception. by default int ,byte are unchecked.

4. AS and IS keyword
Both keywords are used for safe cast typing with lill diff in their working.

IS : 
checks whether the type of an given object is compatible with the new object type and returns Boolean type true or false.

AS:
checks whether the type of an given object is compatible with the new object type and returns object if it is compatible or null if it isn't.

person p = new person();
     Men men = new Men();
  
  Men m2 =  p as Men;
  Console.WriteLine(p is Men);
  Console.WriteLine(men is person);
  if(m2 !=null)
  {
   Console.WriteLine("m is person type");
  }else
  {
     Console.WriteLine("m is not person type");
  }


5. Volatile and Lock keyword
volatile indicates that field can be modified by multiple thread. volatile keyword can be applied only to fields of class/struct.

Lock keyword ensures that if one thread is accessed any object in lock block that will not be accessible by another thread, it will have to wait until that thread release the accessed object.



25 comments:

  1. All the points you described so beautiful. Every time i read your i blog and i am so surprised that how you can write so well.
    Devops training in Chennai
    Devops training in Bangalore
    Devops Online training
    Devops training in Pune

    ReplyDelete
  2. Awesome! Education is the extreme motivation that open the new doors of data and material. So we always need to study around the things and the new part of educations with that we are not mindful.


    angularjs-Training in velachery

    angularjs-Training in annanagar

    angularjs Training in chennai

    angularjs Training in chennai

    ReplyDelete
  3. Nice tips. Very innovative... Your post shows all your effort and great experience towards your work Your Information is Great if mastered very well.
    python training in pune
    python training institute in chennai
    python training in Bangalore

    ReplyDelete
  4. Nice post. By reading your blog, i get inspired and this provides some useful information. Thank you for posting this exclusive post for our vision. 
    apple iphone service center in chennai | apple ipad service center in chennai | apple iphone service center in chennai

    ReplyDelete
  5. Hello I am so delighted I found your blog, I really found you by mistake, while I was looking on Yahoo for something else, anyways I am here now and would just like to say thanks for a tremendous post. Please do keep up the great work.
    Authorized iphone service center in Chennai | iphone service center in chennai | Mobile service center in chennai | Authorized iphone service center in Chennai | iphone service center in chennai

    ReplyDelete
  6. Bagi pemula kalian dapat bermain di meja kecil dulu yaa jangan langsung bermain di meja besar. Karena sebagai pemula kalian tentunya belum begitu paham bagaimana sistem permainannya
    asikqq
    dewaqq
    sumoqq
    interqq
    pionpoker
    bandar ceme terpercaya
    hobiqq
    paito warna terlengkap
    bocoran sgp

    ReplyDelete
  7. microsoft azure cloud services london
    WELCOME TO ANIKA TECH SUPPORT
    Anika Tech Support managed by a team of professionals utilising a combined 20+ years of experience in IT support and Managed IT services Focusing on Proactive support, continuity, growth and development. We are a forward thinking IT Company who support public and private sector using the latest tech as a driving force for our client’s Success.

    ReplyDelete
  8. It was a very good experience,Faculty members are very knowledgeable and cooperative. Specially My trainer teaching more as he focused upon practical rather than theory. All together it was an enlightening and informative course.

    SAP HANA training institutes in bangalore

    SAP HANA training in bangalore

    Best SAP HANA training institutes in bangalore

    SAP HANA training course content

    SAP HANA training interview questions

    SAP HANA training & placement in bangalore

    SAP HANA training center in bangalore

    ReplyDelete
  9. This post is really nice and informative. The explanation given is really comprehensive and useful.

    sap business intelligence training

    ReplyDelete
  10. Thanks you for sharing this unique useful information content with us...
    Devops Training in Bangalore

    ReplyDelete
  11. The blog is very useful and informative thanks for sharing SD WAN TRAINING

    ReplyDelete
  12. I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.


    sap bw on hana tutorial

    ReplyDelete
  13. It was so nice content.I was really satisfied by seeing this content.
    sap hybris training in bangalore

    ReplyDelete
  14. First You got a great blog .I will be interested in more similar topics. i see you got really very useful topics, i will be always checking your blog thank. sap hana training in bangalore

    ReplyDelete