Showing posts with label c# interview questions. Show all posts
Showing posts with label c# interview questions. Show all posts

Thursday, 4 June 2020

C# Quiz Part-2


 C# Quiz Part-2


11. Can Abstract Class have Constructor?
     A. 
     B. 
     C. 
     D. 
... Answer is A)
Yes, Abstract class can have constructor and also can cal from derived class



12. Static variable is called using class name but cannot be call static variable through object?
     A. 
     B. 
     C. 
     D. 
... Answer is A)
True , Only one copy of static variable is create and used every where



13. In case of dynamic variable ?
     A. 
     B. 
     C. 
     D. 
... Answer is C)
Type of the variable is decided at run time



14. The process of Converting a Value Type to a Reference Type(object) is called ?
     A. 
     B. 
     C. 
     D. 
... Answer is A)
Boxing



15. File.AppendText() is used to create a StreamWriter ?
     A. 
     B. 
     C. 
     D. 
... Answer is B)
Appends UTF-8 encoded text to an existing file



16.  ?? operator In C# is called Null-coalescing operator which ? 
     A. Is used to check null values.
     B.
     C. 
     D. 
... Answer is A)
used to check null values



17.  In c# File.Move() method is used to move a specified file to a new location ? 
     A. True
     B. 
     C. Can't say .
     D. 
... Answer is A)
True 



18. UInt32 is used to represents ?
     A. 64-bit unsigned integer
     B. 
     C. 32-bit unsigned integer
     D. 
... Answer is C)
32-bit unsigned integer



19. In c# Anonymous type is created  ?
     A.Using the new keyword
     B. It is a reference type data type
     C. Property, event and indexer cannot be an anonymous types.
     D. 
... Answer is D)
All of them

 
 
20. Enum is mainly used to assign the names or string values to integral constants which is a ? 
     A.Value Type
     B. Reference Type
     C. 
     D. 
... Answer is A)
Value Type





Thank You



c# quiz part-1


 C# Quiz Part-1


1. Static constructor is used to initialize ?
     A. 
     B. 
     C. 
     D. 
... Answer is B)
Static data members



2. The members which is declared as private are available only ?
     A. 
     B. 
     C. 
     D. 
... Answer is C)
With in the containing type only



3. The members which is declared as Internal are available ?
     A. 
     B. 
     C. 
     D. 
... Answer is A)
Any where within the containing assembly



4. Default access modifier of class member is ?
     A. 
     B. 
     C. 
     D. 
... Answer is D)
Private



5. Default constructor is classified into two types ?
     A. 
     B. 
     C. 
     D. 
... Answer is C)
Both



6. Copy Constructor is used to ?
     A. Copy one array into another.
     B. Copy o
     C. 
     D. 
... Answer is B)
Copy one object data into another object 



7. Constants in c# are ? 
     A. Mutable
     B. 
     C. Changes their values.
     D. 
... Answer is B)
Immutable 



8. Read-only variable are required to initialize at its declaration ?
     A. True
     B. 
     C. Can't say
     D. 
... Answer is A)
True 



9. In c# Array we can't insert value in the middle ?
     A. True
     B. False
     C. Can't say
     D. 
... Answer is A)
True

 
 
10. ContainKey and ContainValue are two method of HashTable ?
     A. True
     B. False
     C. 
     D. 
... Answer is A)
True 





Thank You



Tuesday, 2 June 2020

1000 C# Facts Part-2 : Access Modifiers



Access Modifiers define the accessibility of a class and its members in a program. It allow you to control access to the class and to restrict the class to be instantiated.

There are mainly 5 different access modifiers available in c#.
1. Private
2. Protected
3. Internal
4. Protected Internal
5. Public

#1. Public: The type (i.e class) or it's member can be accessed by any other code which is either present in the same assembly(dll)  or another assembly that references it. 

Public members are available any where without any restrictions.

   // Declaring employee id and name as public 
    public int employeeId; 
    public string employeeName; 
  
    // Constructor 
    public Student(int r, string name) 
    { 
        employeeId = id ; 
        employeeName = n; 
    } 
  
#2. Private: The members which is declared as private are available only with in the containing type.

   // Declaring employee id  as Private.

    private int employeeId; 

// employeeId will not be available in any other classes except current class.

#3. Protected: The members which is declared as protected are available with in the containing type(i.e same class) and  to the types (classes) that derive from the containing type.

class Color{ 
    // Member colorType declared as protected 
    protected int colorType ;
  
    public Color() 
    { 
        colorType = "red"; 
    } 
  
// class Phone inherits the class Color
class Phone  : Color { 
  
    // Members of Phone class can access member of class 'Color' 
    public int getcolorType() 
    { 
        return colorType; 
    } 

#4. Internal: The members which is declared as Internal are available any where within the containing assembly. 

Compile time error will through when we try to access, an internal member from outside the containing assembly.

#5. Protected Internal:  Protected Internal members can be accessed by any code in the assembly in which it is declared or from within a derived class in another assembly.

It is a combination of protected and internal. If you have understood protected and internal, this should be very easy to follow.

Key Facts About Access Modifiers : 

 >  Default access modifier of class is Internal. 
 >  Default access modifier of class member is private. 
 >  Access modifiers are not allowed on static constructors.
  Static keyword is used to access members of class before the object creation of that class.
 >  An object of a derived class cannot access the private member of the base class.
 >  The main()method is declared private by default if no other access specifier is used for it.




Thank You