Showing posts with label C# interview Questions. Show all posts
Showing posts with label C# interview Questions. Show all posts

C# Interview Questions and Answers

How do you mark a method obsolete?
[Obsolete] public int Foo() {...}
or
[Obsolete(\"This is a message describing why this method is obsolete\")] public int Foo() {...}
Note: The O in Obsolete is always capitalized.

C# interview questions and answers


What's C# ?
C# (pronounced C-sharp) is a new object oriented language from Microsoft and is derived from C and C++. It also borrows a lot of concepts from Java too including garbage collection.

C# interview questions and answers


  1. What’s the advantage of using System.Text.StringBuilder over System.String? 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.

Generic classses

Generic classes encapsulate operations that are not specific to a particular data type. The most common use for generic classes is with collections like linked lists, hash tables, stacks, queues, trees and so on where operations such as adding and removing items from the collection are performed in much the same way regardless of the type of data being stored.

MODIFIERS -INTERVIEW QUESTIONS

Q: How can I prevent inheritance without marking a class final?

A: Declaring a class final is the simplest way to prevent extension. A more limited way to control overrides without preventing extension is to declare individual methods final. If all methods are declared final but not the class, the class may be extended but none of its methods overridden.

C# Interview Questions & Answers :

1. Does C# support multiple-inheritance?
No.

2. Who is a protected class-level variable available to?

It is available to any sub-class (a class inheriting this class).

3. Are private class-level variables inherited?

Yes, but they are not accessible. Although they are not visible or accessible via the class interface, they are inherited.

4. Describe the accessibility modifier “protected internal”.

It is available to classes that are within the same assembly and derived from the specified base class.

5. What’s the top .NET class that everything is derived from?

System.Object.

6. What does the term immutable mean?

The data value may not be changed. Note: The variable value may be changed, but the original immutable data value was discarded and a new data value was created in memory.

7. What’s the difference between System.String and System.Text.StringBuilder classes?

System.String is immutable. System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.

8. What’s the advantage of using System.Text.StringBuilder over System.String?

StringBuilder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable, so each time a string is changed, a new instance in memory is created.