a component
2. What is C# (C-Sharp) ?
9. This is because they all
have the same
An Programming Language
familiar Windows ___ at their
core.
3. C# (C-Sharp) belong to
which framework ?
IDE
.NET
10. What is OLE ?
4. What is CLR ?
Object Linking and Embedding
translator
templates
14. ____ this is a minimum
7. Using C# you can, for
set of standards that
example, write a ___ web
guarantees that code can be
page
accessed from any language.
static
Common Type System
8. Using C# you can, for
15. Common Language
1.Does C# support multiple-inheritance?
No. But you can use Interfaces.
Specification: This is a
minimum set of standards that 2.Where is a protected class-level variable
guarantees that code can be available?
It is available to any sub-class derived from base
accessed from any class
area) where all C# objects 13.What’s the .NET collection class that allows an
live. element to be accessed using a unique key?
HashTable.
2. When at least one of the methods in the class 5. What are the different ways a method can be
is abstract. overloaded?
Different parameter data types, different number
of parameters, different order of parameters.
6.What is an interface class?
Interfaces, like classes, define a set of properties, 6. If a base class has a number of overloaded
methods, and events. But unlike classes, constructors, and an inheriting class has a
interfaces do not provide implementation. They number of overloaded constructors; can you
are implemented by classes, and defined as enforce a call from an inherited constructor to a
separate entities from classes. specific base constructor?
Yes, just place a colon, and then keyword base
7.Why can’t you specify the accessibility modifier (parameter list to invoke the appropriate
for methods inside the interface? constructor) in the overloaded constructor
They all must be public, and are therefore public definition inside the inherited class.
by default.
10. What’s the top .NET class that everything is 22. And if they have conflicting method names?
derived from? It’s up to you to implement the method inside
System.Object. your own class, so implementation is left entirely
up to you.
11. How’s method overriding different from This might cause a problem on a higher-level
overloading? scale if similarly named methods from different
When overriding, you change the method interfaces expect different data, but as far as
behavior for a derived class. Overloading simply compiler cares you’re okay.
involves having a method with the same name
within the class. 23. What’s the difference between an interface
and abstract class?
12. What does the keyword virtual mean in the In the interface all methods must be abstract, in
method definition? the abstract class some methods can be concrete.
The method can be over-ridden. In the interface no accessibility modifiers are
allowed, which is ok in abstract classes.
13. Can you declare the override method static
while the original method is non-static? 24. How can you overload a method?
No, you can’t, the signature of the virtual method Different parameter data types, different number
must remain the same, only the keyword virtual is of parameters, different order of parameters.
changed to keyword override.
25. If a base class has a bunch of overloaded
14. Can you override private virtual methods? constructors, and an inherited class has another
No, moreover, you cannot access private methods bunch of overloaded constructors, can you
in inherited classes, have to be protected in the enforce a call from an inherited constructor to an
base class to allow any sort of access. arbitrary base constructor?
Yes, just place a colon, and then keyword base
15. Can you prevent your class from being (parameter list to invoke the appropriate
inherited and becoming a base class for some constructor) in the overloaded constructor
other classes? definition inside the inherited class.
Yes, that’s what keyword sealed in the class
26. What’s the difference between System.String immutable, so each time a string is
and System.StringBuilder classes?
System.String is immutable, System.StringBuilder changed, a new instance in memory is
was designed with the purpose of having a created.
mutable string where a variety of operations can
be performed. 9. Can you store multiple data
types in System.Array?
27. Is it namespace class or class namespace?
The .NET class library is organized into No.
namespaces. Each namespace contains a 10. What’s the difference between
functionally related group of classes so natural
namespace comes first. the System.Array.CopyTo() and
System.Array.Clone() ?
2. Who is a protected class-level
The Clone() method returns a new
variable available to?
array (a shallow copy) object
It is available to any sub-class (a class
containing all the elements in the
inheriting this class).
original array. The CopyTo() method
3. Are private class-level variables
copies the elements into another
inherited?
existing array. Both perform a shallow
Yes, but they are not accessible.
copy. A shallow copy means the
Although they are not visible or
contents (each array element)
accessible via the class interface, they
contains references to the same object
are inherited.
as the elements in the original array. A
4. Describe the accessibility
deep copy (which neither of these
modifier “protected internal”.
methods performs) would create a
It is available to classes that are within
new instance of each element's object,
the same assembly and derived from
resulting in a different, yet identacle
the specified base class.
object.
5. What’s the top .NET class that
11. How can you sort the
everything is derived from?
elements of the array in
System.Object.
descending order?
6. What does the term immutable
By calling Sort() and then Reverse()
mean?
methods.
The data value may not be changed.
12. What’s the .NET collection
Note: The variable value may be
class that allows an element to be
changed, but the original immutable
accessed using a unique key?
data value was discarded and a new
HashTable.
data value was created in memory.
13. What class is underneath the
7. What’s the difference between
SortedList class?
System.String and
A sorted HashTable.
System.Text.StringBuilder
14. Will the finally block get
classes?
executed if an exception has not
System.String is immutable.
occurred?
System.StringBuilder was designed
Yes.
with the purpose of having a mutable
15. What’s the C# syntax to catch
string where a variety of operations
any possible exception?
can be performed.
A catch block that catches the
8. What’s the advantage of using
exception of type System.Exception.
System.Text.StringBuilder over
You can also omit the parameter data
System.String?
type in this case and just write catch
StringBuilder is more efficient in cases
{}.
where there is a large amount of
16. Can multiple catch blocks be
string manipulation. Strings are
executed for a single try
statement? space or symbol like ? - + ! @ # % & *
No. Once the proper catch block ( ) { } [ ] , : ; ‘ “ \ and/. However an
processed, control is transferred to the underscore _ can be used wherever a
finally block (if there are any). space is required.
17. Explain the three services • Must be unique
model commonly know as a three- • Can have any number of characters
tier application. • Keywords cannot be used as variable
Presentation (UI), Business (logic and names.
underlying code) and Data (from
storage or other sources). 4) What are the different types of
Data?
C# Interview Questions | C Sharp There are two different types of data
Interview Questions supported by C#. They are
1) Value types: -They directly contain
1) Explain about C#? data. When you declare an int
C # is also known as c sharp. It is a variable, the system allocates memory
programming language introduced by to store the value.
Microsoft. C# contains features similar 2) Reference type: -The reference
to Java and C++. It is specially types do not maintain data but they
designed to work with Microsoft .NET contain a reference to the variables,
platform. which are stored in memory. This
2) Explain about the rules for means that if the value in the memory
naming classes in C#? location is modified by one of the
These are the rules for naming classes variables, the other variables
in c sharp. automatically reflect the changes
• Must begin with a letter. This letter value
may be followed by a sequence of 5) Explain about member
letters, digits (0-9), or ‘_’. The first functions?
character in a class name cannot be a A function is a set of statements that
digit. perform a specific task in response to
• Must not contain any embedded a message. The functions of a class
space or symbol like ? - + ! @ # % & * are called member functions in
( ) { } [ ] , : ; ‘ “ \ and/. However an Csharp. Member functions are
underscore _ can be used wherever a declared inside the class. The function
space is required. declaration introduces the function in
• Must not use a keyword for a class the class and the function definition
name. contains the function code.
3) What are the rules to be 6) Explain about comment entry?
followed while naming variables in Comments are a part of the program
C#. and are used to explain the code.
The following rules are used for Compilers ignore comment entries. If a
naming variables in C#. comment entry spans more than one
* Must begin with a letter or an line, it has to be enclosed within ‘/*’
underscore _ which may be followed and ‘*/’. The symbol ‘//’ treats the rest
by a sequence of letters, digits (0-9), of code within the same line as a
or ‘_’. The first character in a variable comment.
name cannot be a digit.
* Must not contain any embedded
7) What are operators? member functions from other class
Applications use operators to process objects and functions. Therefore, the
the data entered by a user. Operators private member of a class is not
like + and – are used to process visible outside a class. If a member is
variables and return a value. An declared private, only the functions of
operator is a set of one or more that class can access the member.
characters that is used for Even the instance of the class cannot
computations or comparisons. access its members
Operators can transform one or more
data values, called operands into a 12) Explain about protected
new data value. internal access specifier?
This specifier allows a class to hide its
8) Explain about the break member variables and member
statement? functions to be accessed from other
A break statement is used to exit the class objects and functions, except the
switch statement. This prevents the child class, within the application. The
execution of the remaining case protected internal access specifier
structures by ending the execution of becomes important while
the switch case construct. Each break implementing inheritance.
statement terminates the enclosing
switch statement and the flow of 13) Define parameter by value?
control. If none of the cases match the Pass by value is the default
default case is invoked. mechanism for passing parameters to
a method. The simplest definition of a
9) Define encapsulation? value parameter is a data type name
Encapsulation literally means to followed by a variable name. When a
enclose in or as if in a capsule. method is called, a new storage
Encapsulation is defined as the location is created for each value
process of enclosing one or more parameter. The values of the
items within a physical or logical corresponding expressions are copied
package. It involves preventing access into them. The expression supplied for
to nonessential details. each value parameter must be similar
to the declaration of the value
10) Define access specifier with parameter.
reference to class?
An access specifier defines the scope 14) State the methods through
of a class member. A class member which parameters can be passed?
refers to the variables and functions in Parameters can be passed by using
a class. A program can have one or any one of the following mechanism.
more classes. You may want some Value: -They are sometimes called in
members of a class to be accessible to or out parameters; therefore, the data
other classes. But, you may not want can be transferred into the method
some other members of the class to but cannot be transferred out.
be accessible outside the class. Reference: -Are sometimes called in or
out parameters, therefore, the data
11) Describe about private access can be transferred into the method
specifier? and out again.
The private access specifier allows a Output: -Are sometimes called out
class to hide its member variables and parameters, data can be transferred
out of the method.
15) Explain about reference
parameter?
A reference parameter is a reference
to a memory location of a data
member. Unlike a value parameter, a
reference parameter does not create a
new storage location. Instead a
reference parameter represents the
same location in memory as the
variable that is supplied in the method
call.