Sei sulla pagina 1di 11

C#.

Net Interview Question and Answers


1. What is C#?

C# (pronounced "C sharp") is a simple, modern, object-oriented, and type-safe programming language. t !ill immediately be familiar to C and C"" programmers. C# combines the high producti#ity of $apid %pplication &e#elopment ($%&) languages. 'here are ( types of comments in C#. )ingle line (**) +ulti (*, ,*) -age*.+/ Comments (***). 0amespace is a logical grouping of class. using )ystem2 using )ystem.Collections.3eneric2 using )ystem.Windo!s.4orms2 'here are se#eral characteristics of C# are 5 )imple 'ype safe 4le6ible 7bject oriented Compatible Consistent nteroperable +odern

2. What are the types of comment in C#?


3. What are the namespaces used in C#.01'?


4. What are the characteristics of C#?


5. 8o! does C# differ from C""?


C# does not support #include statement. t uses only using statement. n C# , class definition does not use a semicolon at the end.

C# does not support multiple code inheritance. Casting in C# is much safer than in c"". n C# s!itch can also be used on string #alues. Command line parameters array beha#e differently in C# as compared to C"". t is necessary to understand some of the concepts used e6tensi#ely in object oriented programming.'hese include 7bjects Classes &ata abstraction and encapsulation nheritance -olymorphism &ynamic 9inding +essage passing.

6. What are the basic concepts of object oriented programming?

7. Can you inherit multiple interfaces? :es. +ultiple interfaces may be inherited in C#. 8. What is inheritance? nheritance is deri#ing the ne! class from the already e6isting one. 9. &efine scope? )cope refers to the region of code in !hich a #ariable may be accessed. 10. What is the difference bet!een public, static and #oid?

u!"i# $'he ;ey!ord public is an access modifier that tells the C# compiler that the +ain method is accessible by anyone. stati# $'he ;ey!ord static declares that the +ain method is a global one and can be called !ithout creating an instance of the class. 'he compiler stores the address of the method as the entry point and uses this information to begin e6ecution before any objects are created. void $ 'he ;ey!ord #oid is a type modifier that states that the +ain method does not return any #alue.

11. What are the modifiers in C#?

%bstract

)ealed <irtual Const 1#ent 16tern 7#erride $eadonly )tatic 0e! %ccess modifiers in C# are 5 public protect pri#ate internal internal protect

12. What are the types of access modifiers in C#?


13. What is bo6ing and unbo6ing? mplicit con#ersion of #alue type to reference type of a #ariable is ;no!n as 97. 03, for e6ample integer to object type con#ersion. Con#ersion of reference type #ariable bac; to #alue type is called as =n9o6ing. 14. What is object? %n object is an instance of a class. %n object is created by using operator ne!. % class that creates an object in memory !ill contain the information about the #alues and beha#iours (or methods) of that specific object. 15. Where are the types of arrays in C#?

)ingle-&imensional +ultidimensional >agged arrays.

16. What is the difference bet!een 7bject and nstance? %n instance of a user-defined type is called an object. We can instantiate many objects from

one class. %n object is an instance of a class. 17. &efine destuctors? % destructor is called for a class object !hen that object passes out of scope or is e6plicitly deleted.% destructors as the name implies is used to destroy the objects that ha#e been created by a constructors./i;e a constructor , the destructor is a member function !hose name is the same as the class name but is precided by a tilde. 18. What is the use of enumerated data type? %n enumerated data type is another user defined type !hich pro#ides a !ay for attaching names to numbers thereby increasing comprehensibility of the code. 'he enum ;ey!ord automatically enumerates a list of !ords by assigning them #alues ?,@,A, and so on. 19. &efine Constructors? % constructor is a member function !ith the same name as its class. 'he constructor is in#o;ed !hene#er an object of its associated class is created. t is called constructor because it constructs the #alues of data members of the class. 20. What is encapsulation? 'he !rapping up of data and functions into a single unit (called class) is ;no!n as encapsulation. 1ncapsulation containing and hiding information about an object, such as internal data structures and code. 21. &oes c# support multiple inheritance? 0o,its impossible !hich accepts multi le#el inheritance. 22. What is 10=+? 1num are used to define constants. 23. What is a data set? % &ata)et is an in memory representation of data loaded from any data source. 24. What is the difference bet!een pri#ate and public ;ey!ord?

%rivate $ 'he pri#ate ;ey!ord is the default access le#el and most restricti#e among all other access le#els. t gi#es least permission to a type or type member. % pri#ate member is accessible only !ithin the body of the class in !hich it is declared. %u!"i# $ 'he public ;ey!ord is most liberal among all access le#els, !ith no restrictions to access !hat so e#er. % public member is accessible not only from !ithin, but also from outside, and gi#es free access to any member declared !ithin the body or outside the body.

25. &efine polymorphism? -olymorphism means one name, multiple forms. t allo!s us to ha#e more than one function !ith the same name in a program. t allo!s us to ha#e o#erloading of operators so that an

operation can e6hibit different beha#iours in different instances. 26. What is >agged %rrays?

% jagged array is an array !hose elements are arrays. 'he elements of a jagged array can be of different dimensions and siBes. % jagged array is sometimes called an arra&'o('arra&s.

27. !hat is an abstract base class? %n abstract class is a class that is designed to be specifically used as a base class. %n abstract class contains at least one pure #irtual function. 28. 8o! is method o#erriding different from method o#erloading? When o#erriding a method, you change the beha#ior of the method for the deri#ed class. 7#erloading a method simply in#ol#es ha#ing another method !ith the same name !ithin the class. 29. What is the difference bet!een ref C out parameters? %n argument passed to a ref parameter must first be initialiBed. Compare this to an out parameter, !hose argument does not ha#e to be e6plicitly initialiBed before being passed to an out parameter. 30. What is the use of using statement in C#? 'he using statement is used to obtain a resource, e6ecute a statement, and then dispose of that resource. 31. What is serialiBation? )erialiBation is the process of con#erting an object into a stream of bytes. &e-serialiBation is the opposite process of creating an object from a stream of bytes. )erialiBation * &e-serialiBation is mostly used to transport objects. 32. What are the difference bet!een )tructure and Class?

)tructures are #alue type and Classes are reference type )tructures can not ha#e contractors or destructors. Classes can ha#e both contractors and destructors. )tructures do not support nheritance, !hile Classes support nheritance.

33. What is difference bet!een Class %nd nterface? C"ass 5 is logical representation of object. t is collection of data and related sub procedures !ith defination. Inter(a#e 5 is also a class containg methods !hich is not ha#ing any definations.Class does not support multiple inheritance. 9ut interface can support.

34. What is &elegates? &elegates are a type-safe, object-oriented implementation of function pointers and are used in many situations !here a component needs to call bac; to the component that is using it. 35. What is %uthentication and %uthoriBation? Aut)enti#ation is the process of identifying users. %uthentication is identifying*#alidating the user against the credentials (username and pass!ord). Aut)ori*ation performs after authentication. %uthoriBation is the process of granting access to those users based on identity. %uthoriBation allo!ing access of specific resource to user. 36. What is a base class? % class declaration may specify a base class by follo!ing the class name !ith a colon and the name of the base class. omitting a base class specification is the same as deri#ing from type object. 37. Can DthisE be used !ithin a static method? 0o F'hisG cannot be used in a static method. %s only static #ariables*methods can be used in a static method. 38. What is difference bet!een constants, readonly and, static ?

Constants5 'he #alue canGt be changed. $ead-only5 'he #alue !ill be initialiBed only once from the constructor of the class. )tatic5 <alue can be initialiBed once. C# supports se#eral different ;inds of statements are 9loc; statements &eclaration statements 16pression statements )election statements teration statements >ump statements 'ry catch statements Chec;ed and unchec;ed /oc; statement

39. What are the different types of statements supported in C#?


40. What is an interface class? t is an abstract class !ith public abstract methods all of !hich must be implemented in the inherited classes.

41. !hat are #alue types and reference types? <alue types are stored in the )tac;. 16amples 5 bool, byte, chat, decimal, double, enum , float, int, long, sbyte, short, strut, uint, ulong, ushort. $eference types are stored in the 8eap. 16amples 5 class, delegate, interface, object, string. 42. What is the difference bet!een string ;ey!ord and )ystem.)tring class? )tring ;ey!ord is an alias for )yste.)tring class. 'herefore, )ystem.)tring and string ;ey!ord are the same, and you can use !hiche#er naming con#ention you prefer. 'he )tring class pro#ides many methods for safely creating, manipulating, and comparing strings. 43. What are the t!o data types a#ailable in C#?

<alue type $eference type 'here are three types of Caching 5 7utput Caching5 stores the responses from an asp.net page. 4ragment Caching5 7nly caches*stores the portion of page (=ser Control) &ata Caching5 is -rogrammatic !ay to Cache objects for performance.

44. What are the different types of Caching?


45. What is the difference bet!een Custom Control and =ser Control? Custo+ Contro"s are compiled code (&lls), easier to use, difficult to create, and can be placed in toolbo6. &rag and &rop controls. %ttributes can be set #isually at design time. Can be used by +ultiple %pplications ( f )hared &lls), 1#en if -ri#ate can copy to bin directory of !eb application add reference and use. 0ormally designed to pro#ide common functionality independent of consuming %pplication. ,ser Contro"s are similar to those of %)- include files, easy to create, can not be placed in the toolbo6 and dragged - dropped from it. % =ser Control is shared among the single application files. 46. What is methods? % method is a member that implements a computation or action that can be performed by an object or class. )tatic methods are accessed through the class. nstance methods are accessed through instances of the class. 47. What is fields? % field is a #ariable that is associated !ith a class or !ith an instance of a class. 48. What is e#ents? %n e#ent is a member that enables a class or object to pro#ide notifications. %n e#ent is

declared li;e a field e6cept that the declaration includes an e#ent ;ey!ord and the type must be a delegate type. 49. What is literals and their types? /iterals are #alue constants assigned to #ariables in a program. C# supports se#eral types of literals are nteger literals $eal literals 9oolean literals )ingle character literals )tring literals 9ac;slash character literals <alue types are stored on the stac; and !hen a #alue of a #ariable is assigned to another #ariable. $eference types are stored on the heap, and !hen an assignment bet!een t!o reference #ariables occurs. C# is a simple and po!erful programming language for !riting enterprise edition applications. 'his is a hybrid of C"" and <9. t retains many C"" features in the area statements,e6pressions, and operators and incorporated the producti#ity of <9. C# helps the de#elopers to easily build the !eb ser#ices that can be used across the nternet through any language, on any platform. C# helps the de#elopers accomplishing !ith fe!er lines of code that !ill lead to the fe!er errors in the code. C# introduces the considerable impro#ement and inno#ations in areas such as type safety,#ersioning. e#ents and garbage collections. )ynta6 error /ogic error $untime error

50. What is the difference bet!een #alue type and reference type?

51. What are the features of c#?


52. What are the types of errors?


53. What is the difference bet!een brea; and continue statement?

'he !rea- state+ent is used to terminate the current enclosing loop or conditional statements in !hich it appears. We ha#e already used the brea; statement to come out of s!itch statements. 'he #ontinue state+ent is used to alter the seHuence of e6ecution. nstead of coming out of the loop li;e the brea; statement did, the continue statement stops the current iteration and simply returns control bac; to the top of the loop. 54. &efine namespace? 'he namespace are ;no!n as containers !hich !ill be used to organiBe the hierarchical set of .0et classes. 55. What is a code group? % code group is a set of assemblies that share a security conte6t. 56. What are sealed classes in C#? 'he sealed modifier is used to pre#ent deri#ation from a class. % compile-time error occurs if a sealed class is specified as the base class of another class. 57. What is the difference bet!een static and instance methods? % method declared !ith a static modifier is a static method. % static method does not operate on a specific instance and can only access static members. % method declared !ithout a static modifier is an instance method. %n instance method operates on a specific instance and can access both static and instance members. 'he instance on !hich an instance method !as in#o;ed can be e6plicitly accessed as this. t is an error to refer to this in a static method. 58. What are the different types of #ariables in C#?

&ifferent types of #ariables used in C# are 5 static #ariables instance #ariable #alue parameters reference parameters array elements output parameters local #ariables

59. What is meant by method o#erloading? +ethod o#erloading permits multiple methods in the same class to ha#e the same name as long as they ha#e uniHue signatures. When compiling an in#ocation of an o#erloaded method, the compiler uses o#erload resolution to determine the specific method to in#o;e

60. What is parameters? -arameters are used to pass #alues or #ariable references to methods. 'he parameters of a method get their actual #alues from the arguments that are specified !hen the method is in#o;ed. 'here are four ;inds of parameters5 #alue parameters, reference parameters, output parameters, and parameter arrays. 61. s C# is object oriented? :1s, C# is an 77 langauge in the tradition of >a#a and C"". 62. What is the difference bet!een %rray and %rraylist? %n array is a collection of the same type. 'he siBe of the array is fi6ed in its declaration. % lin;ed list is similar to an array but it doesnGt ha#e a limited siBe. 63. What are the special operators in C#?

C# supports the follo!ing special operators. is (relational operator) as (relational operator) typeof (type operator) siBeof (siBe operator) ne! (object creator) .dot (member access operator) chec;ed (o#erflo! chec;ing) unchec;ed (pre#ention of o#erflo! chec;ing)

64. What is meant by operators in c#? %n operator is a member that defines the meaning of applying a particular e6pression operator to instances of a class. 'hree ;inds of operators can be defined5 unary operators, binary operators, and con#ersion operators. %ll operators must be declared as public and static. 65. What is a parameteriBed type? % parameteriBed type is a type that is parameteriBed o#er another #alue or type. 66. What are the features of abstract class?

%n abstract class cannot be instantiated, and it is an error to use the ne! operator on an abstract class. %n abstract class is permitted (but not reHuired) to contain abstract methods and accessors. %n abstract class cannot be scaled.

67. What is the use of abstract ;ey!ord? 'he modifier a!stra#t is a ;ey!ord used !ith a class, to indicate that this class cannot itself ha#e direct instances or objects, and it is intended to be only a IbaseI class to other classes. 68. What is the use of goto statement? 'he goto statement is also included in the C# language. 'his goto can be used to jump from inside a loop to outside. 9ut jumping from outside to inside a loop is not allo!ed. 69. What is the difference bet!een console and !indo! application?

% console application, !hich is designed to run at the command line !ith no user interface. % Windo!s application, !hich is designed to run on a userGs des;top and has a user interface. 'he return statement is associated !ith procedures (methods or functions). 7n e6ecuting the return statement, the system passes the control from the called procedure to the calling procedure. 'his return statement is used for t!o purposes 5 to return immediately to the caller of the currently e6ecuted code to return some #alue to the caller of the currently e6ecuted code.

70. What is the use of return statement?

71. What is the difference bet!een %rray and /in;ed/ist? %rray is a simple seHuence of numbers !hich are not concerned about each others positions. they are independent of each others positions. adding,remo#ing or modifying any array element is #ery easy. Compared to arrays ,lin;ed list is a comlicated seHuence of numbers. 72. &oes C# ha#e a thro!s clause? 0o, unli;e >a#a, C# does not reHuire the de#eloper to specify the e6ceptions that a method can thro!. 73. &oes C# support a #ariable number of arguments? :es, uisng the params ;ey!ord. 'he arguments are specified as a list of arguments of a specific type. 74. Can you o#erride pri#ate #irtual methods? 0o, pri#ate methods are not accessible outside the class. 75. What is a multi cast delegates? t is a delegate that points to and e#entually fires off se#eral methods.

Potrebbero piacerti anche