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

Thursday, 24 May 2018

Multiple Catch Blocks for Try Block in C#



              In this article, I would like to know you about multiple catch blocks for try block.
Actually the Exception class is the super class for all the exceptions, so this Exception class catch block should be at end of all catch blocks, if not it shows an error message at compile time only i.e., A previous catch clause already catches all exceptions of this or of a super type ('Exception').
So that to avoid compile time errors, we have to set the order of different exception catch blocks.

Friday, 11 May 2018

Difference between constant and read-only in C#


                             Constant and readonly keywords in C# are used to maintain the value throughout the application without any change. But constant should be assigned a value at the time of declaration only, but there is no need to assigned value at the time of declaration of readonly variable, can be assigned a value in constructor. The following example shows below clarifies about the constant and readonly.

Difference Between string and StringBuilder in C#


    String is class and string is datatype, string is alias name of String, so there is no difference between string and String. String is immutable which cannot change in size and StringBuilder is mutable which can change in size. The following example shows the difference between string and StringBuilder.

Tuesday, 25 July 2017

Difference between Interface and Abstract Class In C# ?

Interface
Abstract Class
  
         Interface Keyword is given before the name of the Interface
                public interface IAbc
        {
            ////
        }



Abstract keyword is used before the name  of the class
       public abstract class Abc
        {
            ////
  }

Saturday, 1 July 2017

Difference between Value Type and Reference Type?




Value Type


Reference Type

i)   Value Type variable contains the value
     itself.


i)        Reference Type variable that contains
       reference or address of the actual data.


ii)    Value Type stores data in  stack.

Eg:-

int a = 100;

                       



100           
a
    



Stack memory


iii)      Reference Type stores data in managed
        heap and stores address of the data in
        stack.

Eg:-
              
int a=100;
Object obj1 = a;

                

Heap memory



100



                                                      1002
                                |
                                |
                                |
                                |
                       
   |

  ↓
1002         
obj1
    

100
a
Stack memory

               
                



iv)                 Value Types are:-
a)      Integral types (sbyte, byte, short, ushort, int, uint, long, ulong)
b)      Bool type
c)       Char type
d)      Floating point type (float, double)
e)      Decimal type
f)       Struct types
g)      Enumeration types


iv)                     Reference Types are :-
a)      Object type
b)      Class type
c)       Interfaces
d)      Delegates
e)      String type
f)       arrays