Note: Click on Link to open/visit that Page
C# Interview Questions1
C# Interview Questions 2
C# Interview Questions 3
C# Interview Questions 4
C# Interview Questions 5
C# Interview Questions 6
C# Interview Questions 7
C# Interview Questions 8
search topic
Monday, October 6, 2008
C# Interview Questions
Tuesday, May 13, 2008
C# Interview Questions -1
Question: What’s the implicit name of the parameter that gets passed into the class’ set method?
Answer: Value, and its datatype depends on whatever variable we’re changing.
Question: How do you inherit from a class in C#?
Answer Place a colon and then the name of the base class. Notice that it’s double colon in C++.
Question: Does C# support multiple inheritance?
Answer No, use interfaces instead.
Question When you inherit a protected class-level variable, who is it available to?
Answer: Classes in the same namespace.
Question Are private class-level variables inherited?
Answer: Yes, but they are not accessible, so looking at it you can honestly say that they are not inherited. But they are.
Question Describe the accessibility modifier protected internal.
Answer: It’s available to derived classes and classes within the same Assembly (and naturally from the base class it’s declared in).
Question C# provides a default constructor for me. I write a constructor that takes a string as a parameter, but want to keep the no parameter one. How many constructors should I write?
Answer: Two. Once you write at least one constructor, C# cancels the freebie constructor, and now you have to write one yourself, even if there’s no implementation in it.
Question What’s the top .NET class that everything is derived from?
Answer: System.Object.
Question How’s method overriding different from overloading?
Answer: When overriding, you change the method behavior for a derived class. Overloading simply involves having a method with the same name within the class.
Question What does the keyword virtual mean in the method definition?
Answer: The method can be over-ridden.
Question Can you declare the override method static while the original method is non-static?
Answer: No, you can’t, the signature of the virtual method must remain the same, only the keyword virtual is changed to keyword override.
C# Interview Questions -2
Question Can you override private virtual methods?
Answer: No, moreover, you cannot access private methods in inherited classes, have to be protected in the base class to allow any sort of access.
Question Can you prevent your class from being inherited and becoming a base class for some other classes?
Answer: Yes, that’s what keyword sealed in the class definition is for. The developer trying to derive from your class will get a message: cannot inherit from Sealed class WhateverBaseClassName. It’s the same concept as final class in Java.
Question Can you allow class to be inherited, but prevent the method from being over-ridden?
Answer: Yes, just leave the class public and make the method sealed.
Question What’s an abstract class?
Answer: A class that cannot be instantiated. A concept in C++ known as pure virtual method. A class that must be inherited and have the methods over-ridden. Essentially, it’s a blueprint for a class without any implementation.
Question When do you absolutely have to declare a class as abstract (as opposed to free-willed educated choice or decision based on UML diagram)?
Answer: When at least one of the methods in the class is abstract. When the class itself is inherited from an abstract class, but not all base abstract methods have been over-ridden.
Question What’s an interface class?
Answer: It’s an abstract class with public abstract methods all of which must be implemented in the inherited classes.
Question Why can’t you specify the accessibility modifier for methods inside the interface?
Answer: They all must be public. Therefore, to prevent you from getting the false impression that you have any freedom of choice, you are not allowed to specify any accessibility, it’s public by default.
Question Can you inherit multiple interfaces?
Answer: Yes, why not.
Question And if they have conflicting method names?
Answer: It’s up to you to implement the method inside your own class, so implementation is left entirely up to you. This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data, but as far as compiler cares you’re okay.
C# Interview Questions -3
Question What’s the difference between an interface and abstract class?
Answer: In the interface all methods must be abstract; in the abstract class some methods can be concrete. In the interface no accessibility modifiers are allowed, which is ok in abstract classes.
Question How can you overload a method?
Answer: Different parameter data types, different number of parameters, different order of parameters.
Question If a base class has a bunch of overloaded constructors, and an inherited class has another bunch of overloaded constructors, can you enforce a call from an inherited constructor to an arbitrary base constructor?
Answer: Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.
Question What’s the difference between System.String and System.StringBuilder classes?
Answer: System.String is immutable; System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.
Question What’s the advantage of using System.Text.StringBuilder over System.String?
Answer: StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each time it’s being operated on, a new instance is created.
Question Can you store multiple data types in System.Array?
Answer: No.
Question What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
Answer: The first one performs a deep copy of the array, the second one is shallow.
Question How can you sort the elements of the array in descending order?
Answer: By calling Sort() and then Reverse() methods.
Question What’s the .NET datatype that allows the retrieval of data by a unique key?
Answer: HashTable.
Question What’s class SortedList underneath?
Answer: A sorted HashTable.
Question Will finally block get executed if the exception had not occurred?
Answer: Yes.
C# Interview Questions -5
Question What’s the difference between XML documentation tag?
Answer: Single line code example and multiple-line code example.
Question Is XML case-sensitive?
Answer: Yes, so
Question What debugging tools come with the .NET SDK?
Answer: CorDBG – command-line debugger, and DbgCLR – graphic debugger. Visual Studio .NET uses the DbgCLR. To use CorDbg, you must compile the original C# file using the /debug switch.
Question What does the This window show in the debugger?
Answer: It points to the object that’s pointed to by this reference. Object’s instance data is shown.
Question What does assert() do?
Answer: In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true.
Question What’s the difference between the Debug class and Trace class?
Answer: Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds.
Question Why are there five tracing levels in System.Diagnostics.TraceSwitcher?
Answer: The tracing dumps can be quite verbose and for some applications that are constantly running you run the risk of overloading the machine and the hard drive there. Five levels range from None to Verbose, allowing to fine-tune the tracing activities.
Question Where is the output of TextWriterTraceListener redirected? To the Console or a text file depending on the parameter passed to the constructor.
Question How do you debug an ASP.NET Web application?
Answer: Attach the aspnet_wp.exe process to the DbgClr debugger.
Question What are three test cases you should go through in unit testing?
Answer: Positive test cases (correct data, correct output), negative test cases (broken or missing data, proper handling), exception test cases (exceptions are thrown and caught properly).
C# Interview Questions -6
Question Can you change the value of a variable while debugging a C# application?
Answer: Yes, if you are debugging via Visual Studio.NET, just go to Immediate window.
Question Explain the three services model (three-tier application). Presentation (UI), business (logic and underlying code) and data (from storage or other sources).
Question What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET?
Answer: SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix, but it’s a .NET layer on top of OLE layer, so not the fastest thing in the world. ODBC.NET is a deprecated layer provided for backward compatibility to ODBC engines.
Question What’s the role of the DataReader class in ADO.NET connections?
Answer: It returns a read-only dataset from the data source when the command is executed.
Question What is the wildcard character in SQL?
Answer: Let’s say you want to query database with LIKE for all employees whose name starts with La. The wildcard character is %, the proper query with LIKE would involve ‘La%’.
Question Explain ACID rule of thumb for transactions. Transaction must be Atomic (it is one unit of work and does not dependent on previous and following transactions), Consistent (data is either committed or roll back, no “in-between” case where something has been updated and something hasn’t), Isolated (no 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).
Question What connections does Microsoft SQL Server support?
Answer: Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and passwords).
Question Which one is trusted and which one is untrusted?
Answer: Windows Authentication is trusted because the username and password are checked with the Active Directory, the SQL Server authentication is untrusted, since SQL Server is the only verifier participating in the transaction.
Question Why would you use untrusted verificaion?
Answer: Web Services might use it, as well as non-Windows applications.
Question What does the parameter Initial Catalog define inside Connection String? The database name to connect to.
Question What’s the data provider name to connect to Access database?
Answer: Microsoft.Access.
Question What does Dispose method do with the connection object?
Answer: Deletes it from the memory.
Question What is a pre-requisite for connection pooling?
Answer: Multiple processes must agree that they will share the same connection, where every parameter is the same, including the security settings.
Thursday, April 17, 2008
C# Interview Questions
The Questions\Tasks:
- Name 10 C# keywords.
- What is public accessibility?
- What is protected accessibility?
- What is internal accessibility?
- What is protected internal accessibility?
- What is private accessibility?
- What is the default accessibility for a class?
- What is the default accessibility for members of an interface?
- What is the default accessibility for members of a struct?
- Can the members of an interface be private?
- Methods must declare a return type, what is the keyword used when nothing is returned from the method?
- Class methods to should be marked with what keyword?
- Write some code using interfaces, virtual methods, and an abstract class.
- A class can have many mains, how does this work?
- Does an object need to be made to run main?
- Write a hello world console application.
- What are the two return types for main?
- What is a reference parameter?
- What is an out parameter?
- Write code to show how a method can accept a varying number of parameters.
- What is an overloaded method?
- What is recursion?
- What is a constructor?
- If I have a constructor with a parameter, do I need to explicitly create a default constructor?
- What is a destructor?
- Can you use access modifiers with destructors?
- What is a delegate?
- Write some code to use a delegate.
- What is a delegate useful for?
- What is an event?
- Are events synchronous of asynchronous?
- Events use a publisher/subscriber model. What is that?
- Can a subscriber subscribe to more than one publisher?
- What is a value type and a reference type?
- Name 5 built in types.
- string is an alias for what?
- Is string Unicode, ASCII, or something else?
- Strings are immutable, what does this mean?
- Name a few string properties.
- What is boxing and unboxing?
- Write some code to box and unbox a value type.
- What is a heap and a stack?
- What is a pointer?
- What does new do in terms of objects?
- How do you dereference an object?
- In terms of references, how do == and != (not overridden) work?
- What is a struct?
- Describe 5 numeric value types ranges.
- What is the default value for a bool?
- Write code for an enumeration.
- Write code for a case statement.
- Is a struct stored on the heap or stack?
- Can a struct have methods?
- What is checked { } and unchecked { }?
- Can C# have global overflow checking?
- What is explicit vs. implicit conversion?
- Give examples of both of the above.
- Can assignment operators be overloaded directly?
- What do operators is and as do?
- What is the difference between the new operator and modifier?
- Explain sizeof and typeof.
- What does the stackalloc operator do?
- Contrast ++count vs. count++.
- What are the names of the three types of operators?
- An operator declaration must include a public and static modifier, can it have other modifiers?
- Can operator parameters be reference parameters?
- Describe an operator from each of these categories:
Arithmetic
Logical (boolean and bitwise)
String concatenation
Increment, decrement
Shift
Relational
Assignment
Member access
Indexing
Cast
Conditional
Delegate concatenation and removal
Object creation
Type information
Overflow exception control
Indirection and Address - What does operator order of precedence mean?
- What is special about the declaration of relational operators?
- Write some code to overload an operator.
- What operators cannot be overloaded?
- What is an exception?
- Can C# have multiple catch blocks?
- Can break exit a finally block?
- Can continue exit a finally block?
- Write some try…catch…finally code.
- What are expression and declaration statements?
- A block contains a statement list {s1;s2;} what is an empty statement list?
- Write some if… else if… code.
- What is a dangling else?
- Is switch case sensitive?
- Write some code for a for loop.
- Can you have multiple control variables in a for loop?
- Write some code for a while loop.
- Write some code for do… while.
- Write some code that declares an array on ints, assigns the values: 0,1,2 to that array and use a foreach to do something with those values.
- Write some code for a collection class.
- Describe Jump statements: break, continue, and goto.
- How do you declare a constant?
- What is the default index of an array?
- What is array rank?
- Can you resize an array at runtime?
- Does the size of an array need to be defined at compile time.
- Write some code to implement a multidimensional array.
- Write some code to implement a jagged array.
- What is an ArrayList?
- Can an ArrayList be ReadOnly?
- Write some code that uses an ArrayList.
- Write some code to implement an indexer.
- Can properties have an access modifier?
- Can properties hide base class members of the same name?
- What happens if you make a property static?
- Can a property be a ref or out parameter?
- Write some code to declare and use properties.
- What is an accessor?
- Can an interface have properties?
- What is early and late binding?
- What is polymorphism
- What is a nested class?
- What is a namespace?
- Can nested classes use any of the 5 types of accessibility?
- Can base constructors can be private?
- object is an alias for what?
- What is reflection?
- What namespace would you use for reflection?
- What does this do? Public Foo() : this(12, 0, 0)
- Do local values get garbage collected?
- Is object destruction deterministic?
- Describe garbage collection (in simple terms).
- What is the using statement for?
- How do you refer to a member in the base class?
- Can you derive from a struct?
- Does C# supports multiple inheritance?
- All classes derive from what?
- Is constructor or destructor inheritance explicit or implicit? What does this mean?
- Can different assemblies share internal access?
- Does C# have “friendship”?
- Can you inherit from multiple interfaces?
- In terms of constructors, what is the difference between: public MyDerived() : base() an public MyDerived() in a child class?
- Can abstract methods override virtual methods?
- What keyword would you use for scope name clashes?
- Can you have nested namespaces?
- What are attributes?
- Name 3 categories of predefined attributes.
- What are the 2 global attributes.
- Why would you mark something as Serializable?
- Write code to define and use your own custom attribute.
- List some custom attribute scopes and possible targets.
- List compiler directives?
- What is a thread?
- Do you spin off or spawn a thread?
- What is the volatile keyword used for?
- Write code to use threading and the lock keyword.
- What is Monitor?
- What is a semaphore?
- What mechanisms does C# have for the readers, writers problem?
- What is Mutex?
- What is an assembly?
- What is a DLL?
- What is an assembly identity?
- What does the assembly manifest contain?
- What is IDLASM used for?
- Where are private assemblies stored?
- Where are shared assemblies stored?
- What is DLL hell?
- In terms of assemblies, what is side-by-side execution?
- Name and describe 5 different documentation tags.
- What is unsafe code?
- What does the fixed statement do?
- How would you read and write using the console?
- Give examples of hex, currency, and fixed point console formatting.
- Given part of a stack trace: aspnet.debugging.BadForm.Page_Load(Object sender, EventArgs e) +34. What does the +34 mean?
- Are value types are slower to pass as method parameters?
- How can you implement a mutable string?
- What is a thread pool?
- Describe the CLR security model.
- What’s the difference between camel and pascal casing?
- What does marshalling mean?
- What is inlining?
- List the differences in C# 2.0.
- What are design patterns?
- Describe some common design patterns.
- What are the different diagrams in UML? What are they used for?