Archive for June 2017
C#.NET Interview Questions and Answers
1. What is C#.NET?
Ans: C#.NET is an object oriented programming language used as code behind language to create .NET applications.2. What is namespace?
Ans: .NET Framework uses namespaces to organize its many classes, as follows: System.Console.WriteLine("Hello World!");System is a namespace and Console is a class in that namespace.
Namespaces are declared at the top of every program as shown below to use classes inside it in the program.
Example: using System;
3. What is the base class for all .NET datatypes?
Ans: The Object Type is the ultimate base class for all data types in C# Common Type System (CTS). Object is an alias for System.Object class. The object types can be assigned values of any other types, value types, reference types, predefined or user-defined types. However, before assigning values, it needs type conversion.
4. What is Boxing in C#.NET?
Ans: When a value type is converted to object type, it is called boxing.5. What is UnBoxing in C#.NET?
Ans: When an object type is converted to a value type, it is called unboxing.6. What are pointer types in C#?
Ans: Pointer type variables store the memory address of another type. Pointers in C# have the same capabilities as the pointers in C or C++.Syntax for declaring a pointer type is −type* identifier;
For example:
char* cptr;
int* iptr;
7. What is encapsulation?
Ans: Encapsulation is defined 'as the process of enclosing one or more items within a physical or logical package'. Encapsulation, in object oriented programming methodology, prevents access to implementation details.8. C#.NET Access specifiers?
Ans: Access specifiers are used to define scope of a type as well as its members ie.,who can access it and who can't access it.
C#.NET supports five different access specifiers. They are:1)Private
2)Public
3)Protected
4)Internal
5)Protected Internal
Default access specifier of method is private.
Default access specifier of class is internal.
Private:Members declared as private cannot be accessed outside the block.
Members declared as private within class or structure aren't possible outside of them in which they are defined.
In C# the default scope for members of a class or structure is "Private".
Public:
Members declared as public can be accessed from anywhere.
Protected:
Members declared as protected can be accessed only in the inherited classes
Internal:
Members declare as internal can be used only with in the project.
Members which are declared as internal were accessible only with in the project both from child or non-child classes.
The default scope for class is Internal.
Protected Internal:
Members declared as Protected Internal, enjoy dual scope ie., Internal and Protected.
Within the project they behave as internal, providing access to all other classes.
Outside the project they behave as Protected, and still provide access to child classes