You are on page 1of 2

Interview Questions

C#
1. Whats the implicit name of the parameter that gets passed into the class set method? Value, and its datatype depends
on whatever variable were changing.
2. How do you inherit from a class in C#? Place a colon and then the name of the base class. Notice that its double colon in
C.
!. Does C# support multiple inheritance? No, use interfaces instead.
". When you inherit a protected class-level variale! who is it availale to? Classes in the same namespace.
#. "re private class-level variales inherited? $es, but they are not accessible, so loo%ing at it you can honestly say that they
are not inherited. &ut they are.
'. Descrie the accessiility modifier protected internal# (ts available to derived classes and classes within the same
)ssembly *and naturally from the base class its declared in+.
,. C# provides a default constructor for me# I write a constructor that ta$es a string as a parameter! ut want to $eep the
no parameter one# How many constructors should I write? -wo. .nce you write at least one constructor, C/ cancels the
freebie constructor, and now you have to write one yourself, even if theres no implementation in it.
0. Whats the top #%&' class that everything is derived from? 1ystem..b2ect.
3. Hows method overriding different from overloading? 4hen overriding, you change the method behavior for a derived
class. .verloading simply involves having a method with the same name within the class.
15. What does the $eyword virtual mean in the method definition? -he method can be over6ridden.
11. Can you declare the override method static while the original method is non-static? No, you cant, the signature of the
virtual method must remain the same, only the %eyword virtual is changed to %eyword override.
12. Can you override private virtual methods? No, moreover, you cannot access private methods in inherited classes, have to
be protected in the base class to allow any sort of access.
1!. Can you prevent your class from eing inherited and ecoming a ase class for some other classes? $es, thats what
%eyword sealed in the class definition is for. -he developer trying to derive from your class will get a message7 cannot inherit
from 1ealed class 4hatever&aseClassName. (ts the same concept as final class in 8ava.
1". Can you allow class to e inherited! ut prevent the method from eing over-ridden? $es, 2ust leave the class public and
ma%e the method sealed.
1#. Whats an astract class? ) class that cannot be instantiated. ) concept in C %nown as pure virtual method. ) class that
must be inherited and have the methods over6ridden. 9ssentially, its a blueprint for a class without any implementation.
1'. When do you asolutely have to declare a class as astract (as opposed to free-willed educated choice or decision
ased on )*+ diagram,? 4hen at least one of the methods in the class is abstract. 4hen the class itself is inherited from
an abstract class, but not all base abstract methods have been over6ridden.
1,. Whats an interface class? (ts an abstract class with public abstract methods all of which must be implemented in the
inherited classes.
10. Why cant you specify the accessiility modifier for methods inside the interface? -hey all must be public. -herefore, to
prevent you from getting the false impression that you have any freedom of choice, you are not allowed to specify any
accessibility, its public by default.
13. Can you inherit multiple interfaces? $es, why not.
25. "nd if they have conflicting method names? (ts up to you to implement the method inside your own class, so
implementation is left entirely up to you. -his might cause a problem on a higher6level scale if similarly named methods from
different interfaces e:pect different data, but as far as compiler cares youre o%ay.
21. Whats the difference etween an interface and astract class? (n the interface all methods must be abstract; in the
abstract class some methods can be concrete. (n the interface no accessibility modifiers are allowed, which is o% in abstract
classes.
22. How can you overload a method? <ifferent parameter data types, different number of parameters, different order of
parameters.
2!. If a ase class has a unch of overloaded constructors! and an inherited class has another unch of overloaded
constructors! can you enforce a call from an inherited constructor to an aritrary ase constructor? $es, 2ust place a
colon, and then %eyword base *parameter list to invo%e the appropriate constructor+ in the overloaded constructor definition
inside the inherited class.
2". Whats the difference etween -ystem#-tring and -ystem#-tring.uilder classes? 1ystem.1tring is immutable;
1ystem.1tring&uilder was designed with the purpose of having a mutable string where a variety of operations can be
performed.
2#. Whats the advantage of using -ystem#'e/t#-tring.uilder over -ystem#-tring? 1tring&uilder is more efficient in the
cases, where a lot of manipulation is done to the te:t. 1trings are immutable, so each time its being operated on, a new
instance is created.
2'. Can you store multiple data types in -ystem#"rray? No.
2,. Whats the difference etween the -ystem#"rray#Copy'o(, and -ystem#"rray#Clone(,? -he first one performs a deep
copy of the array, the second one is shallow.
20. How can you sort the elements of the array in descending order? &y calling 1ort*+ and then =everse*+ methods.
23. Whats the #%&' datatype that allows the retrieval of data y a uni0ue $ey? >ash-able.
!5. Whats class -orted+ist underneath? ) sorted >ash-able.
!1. Will finally loc$ get e/ecuted if the e/ception had not occurred? $es.
!2. Whats the C# e0uivalent of C11 catch (2,! which was a catch-all statement for any possile e/ception? ) catch bloc%
that catches the e:ception of type 1ystem.9:ception. $ou can also omit the parameter data type in this case and 2ust write
catch ?@.
!!. Can multiple catch loc$s e e/ecuted? No, once the proper catch code fires off, the control is transferred to the finally
bloc% *if there are any+, and then whatever follows the finally bloc%.
!". Why is it a ad idea to throw your own e/ceptions? 4ell, if at that point you %now that an error has occurred, then why
not write the proper code to handle that error instead of passing a new 9:ception ob2ect to the catch bloc%A -hrowing your
own e:ceptions signifies some design flaws in the pro2ect.
!#. Whats a delegate? ) delegate ob2ect encapsulates a reference to a method. (n C they were referred to as function
pointers.
!'. Whats a multicast delegate? (ts a delegate that points to and eventually fires off several methods.
!,. Hows the D++ Hell prolem solved in #%&'? )ssembly versioning allows the application to specify not only the library it
needs to run *which was available under 4in!2+, but also the version of the assembly.
!0. What are the ways to deploy an assemly? )n B1( installer, a C)& archive, and CC.P$ command.
!3. Whats a satellite assemly? 4hen you write a multilingual or multi6cultural application in .N9-, and want to distribute the
core application separately from the localiDed modules, the localiDed assemblies that modify the core application are called
satellite assemblies.
"5. What namespaces are necessary to create a locali3ed application? 1ystem.ElobaliDation, 1ystem.=esources.
"1. Whats the difference etween 44 comments! 45 54 comments and 444 comments? 1ingle6line, multi6line and CBF
documentation comments.
"2. How do you generate documentation from the C# file commented properly with a command-line compiler? Compile it
with a Gdoc switch.
"!. Whats the difference etween 6c7 and 6code7 8*+ documentation tag? 1ingle line code e:ample and multiple6line
code e:ample.
"". Is 8*+ case-sensitive? $es, so H1tudentI and HstudentI are different elements.
"#. What deugging tools come with the #%&' -D9? Cor<&E J command6line debugger, and <bgCF= J graphic debugger.
Visual 1tudio .N9- uses the <bgCF=. -o use Cor<bg, you must compile the original C/ file using the Gdebug switch.
"'. What does the 'his window show in the deugger? (t points to the ob2ect thats pointed to by this reference. .b2ects
instance data is shown.
",. What does assert(, do? (n debug compilation, assert ta%es in a &oolean condition as a parameter, and shows the error dialog
if the condition is false. -he program proceeds without any interruption if the condition is true.
"0. Whats the difference etween the Deug class and 'race class? Documentation loo$s the same# Kse <ebug class for
debug builds, use -race class for both debug and release builds.
"3. Why are there five tracing levels in -ystem#Diagnostics#'race-witcher? -he tracing dumps can be Luite verbose and for
some applications that are constantly running you run the ris% of overloading the machine and the hard drive there. Mive
levels range from None to Verbose, allowing to fine6tune the tracing activities.
#5. Where is the output of 'e/tWriter'race+istener redirected? -o the Console or a te:t file depending on the parameter
passed to the constructor.
#1. How do you deug an "-:#%&' We application? )ttach the aspnetNwp.e:e process to the <bgClr debugger.
#2. What are three test cases you should go through in unit testing? Positive test cases *correct data, correct output+, negative
test cases *bro%en or missing data, proper handling+, e:ception test cases *e:ceptions are thrown and caught properly+.
#!. Can you change the value of a variale while deugging a C# application? $es, if you are debugging via Visual
1tudio.N9-, 2ust go to (mmediate window.
#". &/plain the three services model (three-tier application,# Presentation *K(+, business *logic and underlying code+ and data
*from storage or other sources+.
##. What are advantages and disadvantages of *icrosoft-provided data provider classes in "D;#%&'? 1OF1erver.N9-
data provider is high6speed and robust, but reLuires 1OF 1erver license purchased from Bicrosoft. .F96<&.N9- is
universal for accessing other sources, li%e .racle, <&2, Bicrosoft )ccess and (nformi:, but its a .N9- layer on top of .F9
layer, so not the fastest thing in the world. .<&C.N9- is a deprecated layer provided for bac%ward compatibility to .<&C
engines.
#'. Whats the role of the Data<eader class in "D;#%&' connections? (t returns a read6only dataset from the data source
when the command is e:ecuted.
#,. What is the wildcard character in -Q+? +ets say you want to 0uery dataase with +I9& for all employees whose
name starts with +a# -he wildcard character is P, the proper Luery with F(Q9 would involve RFaP.
#0. &/plain "CID rule of thum for transactions# -ransaction must be )tomic *it is one unit of wor% and does not dependent
on previous and following transactions+, Consistent *data is either committed or roll bac%, no Sin6betweenT case where
something has been updated and something hasnt+, (solated *no transaction sees the intermediate results of the current
transaction+, <urable *the values persist if the data had been committed even if the system crashes right after+.

You might also like