Anda di halaman 1dari 15

there are any), and then whatever

C# interview questions follows the finally block.


and answers 10.Why is it a bad idea to throw
1. What’s the advantage of using your own exceptions? Well, if at
System.Text.StringBuilder over that point you know that an error
System.String? StringBuilder is has occurred, then why not write the
more efficient in the cases, where a proper code to handle that error
lot of manipulation is done to the instead of passing a new Exception
text. Strings are immutable, so each object to the catch block? Throwing
time it’s being operated on, a new your own exceptions signifies some
instance is created. design flaws in the project.
2. Can you store multiple data 11.What’s a delegate? A delegate

types in System.Array? No. object encapsulates a reference to a


3. What’s the difference between method. In C++ they were referred
the System.Array.CopyTo() and to as function pointers.
System.Array.Clone()? The first 12.What’s a multicast delegate? It’s

one performs a deep copy of the a delegate that points to and


array, the second one is shallow. eventually fires off several methods.
4. How can you sort the elements 13.How’s the DLL Hell problem

of the array in descending solved in .NET? Assembly


order? By calling Sort() and then versioning allows the application to
Reverse() methods. specify not only the library it needs
5. What’s the .NET datatype that to run (which was available under
allows the retrieval of data by a Win32), but also the version of the
unique key?HashTable. assembly.
6. What’s class SortedList 14.What are the ways to deploy an

underneath? A sorted HashTable. assembly? An MSI installer, a CAB


7. Will finally block get executed archive, and XCOPY command.
if the exception had not 15.What’s a satellite

occurred? Yes. assembly? When you write a


8. What’s the C# equivalent of C+ multilingual or multi-cultural
+ catch (…), which was a catch- application in .NET, and want to
all statement for any possible distribute the core application
exception? A catch block that separately from the localized
catches the exception of type modules, the localized assemblies
System.Exception. You can also omit that modify the core application are
the parameter data type in this case called satellite assemblies.
and just write catch {}. 16.What namespaces are
9. Can multiple catch blocks be necessary to create a localized
executed? No, once the proper application?System.Globalization,
catch code fires off, the control is System.Resources.
transferred to the finally block (if
17.What’s the difference same. Use Debug class for debug
between // comments, /* */ builds, use Trace class for both
comments and /// debug and release builds.
comments? Single-line, multi-line 25.Why are there five tracing
and XML documentation comments. levels in
18.How do you generate System.Diagnostics.TraceSwitc
documentation from the C# file her? The tracing dumps can be
commented properly with a quite verbose and for some
command-line applications that are constantly
compiler? Compile it with a /doc running you run the risk of
switch. overloading the machine and the
19.What’s the difference between hard drive there. Five levels range
<c> and <code> XML from None to Verbose, allowing to
documentation tag? Single line fine-tune the tracing activities.
code example and multiple-line code 26.Where is the output of
example. TextWriterTraceListener
20.Is XML case-sensitive? Yes, so redirected? To the Console or a
<Student> and <student> are text file depending on the parameter
different elements. passed to the constructor.
21.What debugging tools come 27.How do you debug an ASP.NET
with the .NET SDK? CorDBG – Web application? Attach the
command-line debugger, and aspnet_wp.exe process to the DbgClr
DbgCLR – graphic debugger. Visual debugger.
Studio .NET uses the DbgCLR. To 28.What are three test cases you
use CorDbg, you must compile the should go through in unit
original C# file using the /debug testing? Positive test cases (correct
switch. data, correct output), negative test
22.What does the This window cases (broken or missing data,
show in the debugger? It points proper handling), exception test
to the object that’s pointed to by this cases (exceptions are thrown and
reference. Object’s instance data is caught properly).
shown. 29.Can you change the value of a
23.What does assert() do? In debug variable while debugging a C#
compilation, assert takes in a application? Yes, if you are
Boolean condition as a parameter, debugging via Visual Studio.NET,
and shows the error dialog if the just go to Immediate window.
condition is false. The program 30.Explain the three services
proceeds without any interruption if model (three-tier
the condition is true. application). Presentation (UI),
24.What’s the difference between business (logic and underlying code)
the Debug class and Trace and data (from storage or other
class? Documentation looks the sources).
31.What are advantages and 35.What connections does
disadvantages of Microsoft- Microsoft SQL Server
provided data provider classes support? Windows Authentication
in ADO.NET? SQLServer.NET data (via Active Directory) and SQL
provider is high-speed and robust, Server authentication (via Microsoft
but requires SQL Server license SQL Server username and
purchased from Microsoft. OLE- passwords).
DB.NET is universal for accessing 36.Which one is trusted and which
other sources, like Oracle, DB2, one is untrusted? Windows
Microsoft Access and Informix, but Authentication is trusted because
it’s a .NET layer on top of OLE layer, the username and password are
so not the fastest thing in the world. checked with the Active Directory,
ODBC.NET is a deprecated layer the SQL Server authentication is
provided for backward compatibility untrusted, since SQL Server is the
to ODBC engines. only verifier participating in the
32.What’s the role of the transaction.
DataReader class in ADO.NET 37.Why would you use untrusted
connections? It returns a read- verificaion? Web Services might
only dataset from the data source use it, as well as non-Windows
when the command is executed. applications.
33.What is the wildcard character 38.What does the parameter
in SQL? Let’s say you want to Initial Catalog define inside
query database with LIKE for Connection String?The database
all employees whose name name to connect to.
starts with La. The wildcard 39.What’s the data provider name
character is %, the proper query with to connect to Access
LIKE would involve ‘La%’. database? Microsoft.Access.
34.Explain ACID rule of thumb for 40.What does Dispose method do
transactions. Transaction must be with the connection
Atomic (it is one unit of work and object? Deletes it from the memory.
does not dependent on previous and 41.What is a pre-requisite for
following transactions), Consistent connection pooling? Multiple
(data is either committed or roll processes must agree that they will
back, no “in-between” case where share the same connection, where
something has been updated and every parameter is the same,
something hasn’t), Isolated (no including the security settings.
transaction sees the intermediate
results of the current transaction),
Durable (the values persist if the
data had been committed even if the
system crashes right after).
SOAP extension then how
this can be achieved. Choose
the correct option from
1. Which of the following can below:
be used to add alternating Answer: One must override
color scheme in a the method ReceiveMessage
Repeater control? 5. Which method do you
Answer: AlternatingItemTem invoke on the
plate DataAdapter control to load
7. The .NET Framework your generated dataset with
provides a runtime data?)
environment called Answer: Fill( )
Answer: CLR 6. Which of the following is
8. If one has two different TRUE about Windows
web form controls in a Authentication in ASP.NET?
application and if one wanted Answer: Automatically
to know whether the values determines role membership
in the above two different 7. The technique that allow
web form control match code to make function calls
what control must be used? to .NET applications on other
Answer: CompareValidator processes and on other
9. The actual work process of machines is
ASP.NET is taken care by Answer: .NET Remoting
Answer: aspnet_wp.exe 8. The type of code found in
10. Give One word: Common Code-Behind class is
type system is built into Answer: Server-side code
which of the following: 9. Which of the following
Answer: CLR transfer execution directly to
13. Find the term: The .NET another page?
framework which provides Answer: Server.Transfer
automatic memory 10. In ASP.NET in form page
management using a the object which contains the
technique called user name is
Answer: Garbage Collection Answer: Page.User.Identity
11. Suppose a .NET
1. The namespace within the programmer wants to
Microsoft .NET framework convert an object into a
which provides the stream of bytes then the
functionality to implement process is called
transaction processing is Answer: Serialization
Answer: System.EnterpriseSe 12. What tags one need to
rvices add within the asp:datagrid
2. What is the base class tags to bind columns
from which all Web forms manually?
inherit? Answer: Set
Answer: Page Class AutoGenerateColumns Proper
3. In ASP.NET the sessions ty to false on the datagrid
can be dumped by using tag
Answer: Session.Abandon 13. In my .NET Framework I
4. Suppose one wants to have threads. Which of the
modify a SOAP message in a
following denote the possible
priority level for the threads? • Session State Service
Answer: All the Above
14. GIVE ONE WORD: In .NET
the operation of reading • Microsoft SQL Server
metadata and using its
contents is known as • All the Above*
Answer: Reflection
15. Which of the following There is a requirement as follows:
allow writing formatted A client side already has 25 COM
output? objects and if the requirement is to
Answer: Response.Output.Wri add a 26th function that must
te() exists only for .NET object without
16. How many classes can a affecting the existing one how to
single .NET DLL contain? achieve the above?
Answer: Many
17. WSDL stands for • By CCW* By RCW
Answer: Web
Services Description Languag
e • None of the Above
An organization has developed a In ASP.NET if one wants to set the
web service in which the values of focus on a particular control
the forms are validated using
ASP.NET application. Suppose this •
web service is got and used by
a customer then in such a scenario
• Call FOCUS method*
which of the following is TRUE

• The customer can run on any 1. On which of the operating
system below ASP.NET can
platform.”* run?
Answer: Both A) and B)
Which of the following denote page
2. There is a requirement as
code model in ASP.NET?
follows:
A client side already has 25
• single-file COM objects and if the
requirement is to add a 26th
function that must exists only
• code-behind for .NET object without
affecting the existing one
• Both A) and B)* how to achieve the above?
Answer: By CCW
In ASP.NET if one wants to maintain
session then which of the following 3. In ASP.NET if one uses
is used? Windows authentication the
current request attaches an
object called as
• In-process storage Answer: WindowsPrincipal
4. In ASP.NET if you want to Answer: Cross Page Posting
allows page developers a way to 6. In ASP.NET if one wants to
specify static connections in set the focus on a particular
a content page then control
the class used is Answer: Call FOCUS method
Answer: ProxyWebPartManager 7. Which of the following is
5. The GridView control in used to write error message
ASP.NET has which of the in event Log File?
following features Answer: System.Diagnostics
Answer: Both A) and B) 8. If in an
6. To set page title ASP.NET application one
dynamically in ASP.NET want to create http handlers
which of the following is which of the interface is used
used? Answer: IHttpHandlerFactory
Answer: < head > section 9. I have an
7. the forms are validated ASP.NET application. I have a
using page loaded from server
ASP.NET application. memory. At this instance
Suppose this which of the following
web service is got and methods gets fired
used by Answer: Load()
a customer then in 10. A developer wanted to
such a scenario which achieve graphics in his
of the following is TRUE display using ASP.NET. Which
Answer: The customer can of the following web controls
run on any platform. are available in ASP.NET to
8. Give one word: What achieve the above?
model does ASP.NET request Answer: AdRotator
processing is based on 11. Which of the following
Answer: Pipeline denote value that can be taken
9. ASP.NET separates the by Cache-Control of ASP.NET?
HTML output from program Answer: All the Above
logic using a feature named 12. Which of the following
as denote page code model in
Answer: Code-behind ASP.NET?
Answer: Both A) and B)
3. In ASP.NET application the 13. The control used in
Global.asax file lie in which ASP.NET to display
directory information from data set but
Answer: ROOT with better formatting and
4. In ASP.NET page editing behavior is
framework an automatic way Answer: DataList
to associate page events and 14. Which of the following
methods is denote New Data-bound
Answer: AutoEventWireup Controls used with ASP.NET
attribute of the Page Answer: All the Above
directive is set to true 15. Which of the following is
5. The feature in ASP.NET 2.0 true about session in
that is used to fire a normal ASP.NET?
postback to a different page Answer: ASP.NET
in the application is called automatically delete sessions
after configurable timeout
interval 1. C# (C-Sharp) was
16. Setting the following developed by
properties for object in
ASP.NET results in
Response.Buffer = True
Response.ExpiresAbsolute =
Now().Subtract(New
TimeSpan(1, 0, 0, 0))
Response.Expires = 0
Response.CacheControl =
"no-cache"
Answer: Avoid page to be
cached
17. In ASP.NET what does the
following return
<%
Response.Write(System.Envir
onment.WorkingSet.ToString(
))
%>
Answer: Gives the memory
working set
18. Forms based
authentication is otherwise
called in ASP.NET as Cookie
Authentication
because Forms authenticatio
n uses cookies to allow
applications to track users
throughout their visit.
Answer: Cookie
Authentication
19. If a developer of ASP.NET
defines style information in a
common location. Then that
location is called as
Answer: Theme
20. Which of the following
denote the web control
associated with Table control
function of ASP.NET?
Answer: TableRow
21. If one uses ASP.NET
configuration system to
restrict access which of the
following is TRUE?
Answer: The access is restricted
only to ASP.NET files
example, write ___ of a
distributed application
Microsoft

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

Common Language Runtime


11. What actually manages
your code ?
5. Object Oriented
Programming (OOP) is a style
CTS
of programming in which your
code is broken up into units,
12. When the . NET runtime
known as
loads and runs code, this is
the language that it expects to
objects and classes
find the code in.

6. There are, however, some


Just-in-Time Compilation
advanced features of C++,
such as __ that are not
13. When you compile
supported in .NET, and are
managed code, the ____
therefore, not available in
actually emits IL.
managed code.

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

3.Are private class-level variables inherited?


Yes, but they are not accessible.
application
4.Describe the accessibility modifier “protected
16. Just-in-Time (JIT) internal”.
Compilation: This is the term It is available to classes that are within the same
assembly and derived from the specified base
for the process of performing class.
the ___ stage of compilation
6.Which class is at the top of .NET class
from IL into native machine hierarchy?
code. System.Object.

7.What does the term immutable mean?


The data value may not be changed.
Note: The variable value may be changed, but the
intermediate original immutable data value was discarded and
a new data value was created in memory.
17. The function call
8.What’s the difference between System.String
generated by a non-OOP and System.Text.StringBuilder classes?
compiler causes what is called System.String is immutable.
System.StringBuilder was designed with the
___ binding purpose of having a mutable string where a
variety of operations can be performed.

9.What’s the advantage of using


strong System.Text.StringBuilder over System.String?

StringBuilder is more efficient in cases where


18. You create a string there is a large amount of string manipulation.
reference: Strings are immutable, so each time a string is
changed, a new instance in memory is created.

10.Can you store multiple data types in


System.Array?
string s; No.

19. When you create a 11.What’s the difference between the


System.Array.CopyTo() and System.Array.Clone()?
reference, you want to The Clone() method returns a new array (a
connect it with a new object. shallow copy) object containing all the elements
in the original array. The CopyTo() method copies
You do so, in general, with the the elements into another existing array. Both
perform a shallow copy. A shallow copy means
the contents (each array element) contains
references to the same object as the elements in
round brackets the original array. A deep copy (which neither of
these methods performs) would create a new
instance of each element's object, resulting in a
20. There are six different different, yet identacle object.
places to store data. This is a
12.How can you sort the elements of the array in
general-purpose pool of descending order?
memory (also in the RAM By calling Sort() and then Reverse() methods.

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.

14.What class is underneath the SortedList class?


The stack A sorted HashTable.
15.Will the finally block get executed if an 9.What happens if you inherit multiple interfaces
exception has not occurred? and they have conflicting method names?
Yes. It’s up to you to implement the method inside
your own class, so implementation is left entirely
16.What’s the C# syntax to catch any possible up to you. This might cause a problem on a
exception? higher-level scale if similarly named methods
A catch block that catches the exception of type from different interfaces expect different data,
System.Exception. You can also omit the but as far as compiler cares you’re okay.
parameter data type in this case and just write
catch {}. 10. What’s the difference between an interface
and abstract class?
17.Can multiple catch blocks be executed for a In an interface class, all methods are abstract -
single try statement? there is no implementation. In an abstract class
No. Once the proper catch block processed, some methods can be concrete. In an interface
control is transferred to the finally block . class, no accessibility modifiers are allowed. An
abstract class may have accessibility modifiers.
18.Explain the three services model commonly
know as a three-tier application? 11. What is the difference between a Struct and a
Presentation (UI), Business (logic and underlying Class?
code) and Data (from storage or other sources). Structs are value-type variables and are thus
saved on the stack, additional overhead but faster
retrieval. Another difference is that structs cannot
Class Questions inherit.
1.What is the syntax to inherit from a class in
C#?
Place a colon and then the name of the base
Method and Property
class. Questions
Example: class MyNewClass : MyBaseClass
1. What’s the implicit name of the parameter that
2.Can you prevent your class from being inherited gets passed into the set method/property of a
by another class? class?
Yes. The keyword “sealed” will prevent the class Value. The data type of the value parameter is
from being inherited. defined by whatever data type the property is
declared .
3.Can you allow a class to be inherited, but
prevent the method from being over-ridden? 2. What does the keyword “virtual” declare for a
Yes. Just leave the class public and make the method or property?
method sealed. The method or property can be overridden.

4.What’s an abstract class? 3. How is method overriding different from


A class that cannot be instantiated. An abstract method overloading?
class is a class that must be inherited and have When overriding a method, you change the
the methods overridden. An abstract class is behavior of the method for the derived class.
essentially a blueprint for a class without any Overloading a method simply involves having
implementation. another method with the same name within the
class.
5.When do you absolutely have to declare a class
as abstract? 4. Can you declare an override method to be
static if the original method is not static?
1. When the class itself is inherited from an No. The signature of the virtual method must
abstract class, but not all base abstract methods remain the same. (Note: Only the keyword virtual
have been overridden. is changed to keyword override)

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.

8.Can you inherit multiple interfaces?


Events and Delegates
Yes. .NET does support multiple interfaces.
1. What’s a delegate?
A delegate object encapsulates a reference to a definition is for. The developer trying to derive
method. from your class will get a message: cannot inherit
from Sealed class WhateverBaseClassName.
2. What’s a multicast delegate? It’s the same concept as final class in Java.
A delegate that has multiple handlers assigned to
it. Each assigned handler (method) is called. 16. Can you allow class to be inherited, but
prevent the method from being over-ridden?
3. What’s the implicit name of the parameter that Yes, just leave the class public and make the
gets passed into the class’ set method? method sealed.
Value, and it’s datatype depends on whatever
variable we’re changing. 17. What’s an abstract class?
A class that cannot be instantiated. A concept in
4. How do you inherit from a class in C#? C++ known as pure virtual method. A class that
Place a colon and then the name of the base must be inherited and have the methods over-
class. ridden.
Essentially, it’s a blueprint for a class without any
5. Does C# support multiple inheritance? implementation.
No, use interfaces instead.
18. When do you absolutely have to declare a
6. When you inherit a protected class-level class as abstract (as opposed to free-willed
variable, who is it available to? educated choice or decision based on UML
Classes in the same namespace. diagram)?
When at least one of the methods in the class is
7. Are private class-level variables inherited? abstract. When the class itself is inherited from an
Yes, but they are not accessible, so looking at it abstract class, but not all base abstract methods
you can honestly say that they are not inherited. have been over-ridden.

8. Describe the accessibility modifier protected 19. What’s an interface class?


internal.? It’s an abstract class with public abstract methods
It’s available to derived classes and classes within all of which must be implemented in the inherited
the same Assembly (and naturally from the base classes.
class it’s declared in).
20. Why can’t you specify the accessibility
9. C# provides a default constructor for me. I modifier for methods inside the interface?
write a constructor that takes a string as a They all must be public. Therefore, to prevent you
parameter, but want to keep the no parameter from getting the false impression that you have
one. How many constructors should I write? any freedom of choice, you are not allowed to
Two. Once you write at least one constructor, C# specify any accessibility, it’s public by default.
cancels the freebie constructor, and now you
have to write one yourself, even if there’s no 21. Can you inherit multiple interfaces?
implementation in it. Yes, why not.

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.

16) How do you use a structure?


A structure is a value type data type.
When you want a single variable to
hold related data of various data
types, you can create a structure. To
create a structure you use the struct
keyword.

17) What is an enumerator?


Enumeration is a value data type,
which means that enumeration
contains its own values and cannot
inherit or pass inheritance.
Enumerator allows you to assign
symbolic names or integral constants.

Anda mungkin juga menyukai