C#.NET Interview Questions And Answers
C#.NET Interview Questions And Answers
In this article, I am going to discuss the most frequently asked 50 C# Interview Questions and Answers. This is part 1 of the C# .NET Interview Questions and Answers article series and hence in this article, we are going to discuss frequently asked basic C# Interview Questions and Answers and in our upcoming articles, we will discuss the experienced Interview questions. As part of this article, we are going to discuss the following C# Interview Questions with Answers.
- What is COM and what are the disadvantages of COM?
- What .NET Represents?
- What is a Framework and what does the .NET Framework provide?
- Explain CLR and its Execution Process.
- What is exactly .NET?
- What are the language and its need?
- What are Technology and its need?
- What is Visual Studio?
- Explain about BCL.
- What is the Just-In-Time (JIT) compilation?
- What are Metadata and an assembly?
- What are the differences between managed code and unmanaged code?
- What is C#?
- What is the difference between an EXE and a DLL?
- What’s the difference between IEnumerable<T> and List<T>?
- Why is class an abstract data type?
- What are the new features introduced in C# 7?
- Why should you override the ToString() method?
- What is the difference between string keyword and System.String class?
- Are string objects mutable or immutable in C#?
- What do you mean by String objects are immutable?
- What is a verbatim string literal and why do we use it?
- How do you create empty strings in C#?
- What is the difference between System.Text.StringBuilder and System.String?
- How do you determine whether a String represents a numeric value?
- What is the difference between int.Parse and int.TryParse methods?
- What are Properties in C#? Explain with an example?
- What are the different types of properties available in C#?
- What are the advantages of using properties in C#?
- What is a static property? Give an example?
- What is Virtual Property in C#? Give an example?
- What is an Abstract Property in C#? Give an example?
- Can you use virtual, override, or abstract keywords on an accessor of a static property?
- What are the 2 broad classifications of data types available in C#?
- How do you create user-defined data types in C#?
- Difference between int and Int32 in C#
- What are the differences between value types and reference types?
- What do you mean by casting a data type?
- What are the 2 kinds of data type conversions available in C#?
- What is the difference between an implicit conversion and an explicit conversion?
- What is the difference between int.Parse and int.TryParse methods?
- What is Boxing and Unboxing in C#?
- What happens during the process of boxing?
- What are Access Modifiers in C#?
- Can we use all access modifiers for all types?
- Can derived classes have greater accessibility than their base types?
- Can the accessibility of a type member be greater than the accessibility of its containing type?
- Can destructors have access modifiers?
- What do protected internal access modifiers mean?
- Can you specify an access modifier for an enumeration?
What is COM?
- COM stands for Component Object Model.
- COM is one of Microsoft Technology. Using this technology we can develop windows applications as well as web applications.
In earlier COM, VB is the programming language that is used to implement windows applications and ASP is used to implement web applications.
What are the disadvantages of COM?
The major two disadvantages of COM is
- Incomplete object-oriented programming means it will not support all the features of OOPs.
- Platform dependent means COM applications can run on only Windows OS.
What .NET Represents?
- NET stands for Network Enabled Technology.
- In .NET dot (.) refers to object-oriented and NET refers to the internet.
So the complete .NET means through object-oriented we can implement internet applications.
What is a Framework?
A framework is a software. Or we can say that a framework is a collection of many small technologies integrated together to develop applications that can be executed anywhere.
What does the .NET Framework provide?
.NET Framework provides two things such as
Explain about BCL.
- Base Class Libraries are designed by Microsoft.
- Without BCL we can’t write any code in .NET so BCL also was known as the Building block of Programs of .NET.
- These are installed into the machine when we installed the .NET framework into the machine.
BCL contains predefined classes and these classes are used for the purpose of application development. The physical location of BCL is C:\Windows\assembly
Explain CLR and its Execution process.
CLR is the core component under the .NET framework which is responsible for converting MSIL code into native code and then execution. Let us understand the Execution flow of CLR with an example. Please have a look at the following code.
In .NET, the code is compiled twice.
- In 1st compilation source code (High-Level Code) is compiled by the respective language compiler and the language compiler generates intermediate code which is also known as MSIL (Microsoft Intermediate Language) or IL (Intermediate language code) Or Managed code.
- In the 2nd compilation, MSIL is converted into Native Code (Machine code) using CLR.
Always 1st compilation is slow and 2nd compilation is first.
What is JIT?
- JIT stands for Just-in-time.
- JIT is the component of CLR that is responsible for converting MSIL code into Native code or Machine code.
- This Native code or Machine code is directly understandable by the operating system.
Explain different types of .NET Framework.
The .Net framework is available in three different types
- .NET Framework: This is the general version required to run .NET applications on Windows OS only.
- .NET mono Framework: This is required if we want to run .NET applications on other OS like Unix, Linux, MAC OS, etc.
- .NET Compact Framework: This is required to run .NET applications on other devices like mobile phones and smartphones.
Note: MSIL is only CPU dependent and will run only on Windows OS only using .NET Framework because .NET Framework is designed for Windows OS only.
There is another company known as “NOVEL” that designed a separate framework known as “MONO Framework”. Using this framework we can run MSIL on different OS Like Linux, UNIX, Mac, BSD, OSX, etc. .NET is platform-dependent using the .NET framework but independent using the MONO framework.
What is not .NET?
- .NET is not an Operating system.
- It is not an application or package.
- .NET is not a database.
- It is not an ERP application.
- .NET is not a Testing Tool.
- It is not a programming language.
What is exactly .NET?
.NET is a framework tool that supports many programming languages and many technologies. It supports 60+ programming languages. In 60+ programming languages, 9 are designed by Microsoft and the remaining are designed by Non-Microsoft.
Microsoft designed programming languages are as follows
- VB.NET
- C#.NET
- VC++.NET
- J#.NET
- F#.NET
- Jscript.NET
- WindowsPowerShell
- Iron Phyton
- Iron Ruby
Technologies supported by the .NET framework are as follows
- ASP.NET (Active Server Pages.NET)
- ADO.NET (Active Data Object.NET)
- WCF (Windows Communication Foundation)
- WPF (Windows Presentation Foundation)
- WWF (Windows Workflow Foundation)
- AJAX (Asynchronous JavaScript and XML)
- LINQ (Language Integrated Query)
- ASP.NET MVC (Model View Controller)
- ASP.NET WEB API
What are the language and its need?
- A language acts as the mediator between the programmer and the system.
- It offers some rules and regulations for writing the program.
- The language also offers some libraries which are required for writing the program.
- The collection of programs is called software.
What are Technology and its needs?
Technology is designed for a particular purpose. For example development of web-related applications in .NET using a technology ASP.NET. But the technology does not offer any specific rules for writing the programs. That’s why technology can’t be implemented individually.
VB.NET, C#.NET both are programming languages. Using these two languages we can implement windows/desktop applications individually. Every language is having its own compiler
VB.NET, C#.NET:
VB.NET and C#.NET both are programming languages. Using these two programming languages we can develop windows applications.
ASP.NET:
- ASP.NET is a part of the .NET Framework.
- ASP.NET is a technology that provides a set of predefined classes. Using these classes we can implement web applications.
- ASP.NET is needed language support.
ADO.NET:
- ADO stands for ActiveX Data Objects.
- The ADO.NET is a .NET database technology.
- ADO.NET provides a set of predefined classes. Using these predefined classes we can perform the operations with the database server.
WCF:
- WCF stands for Windows Communication Foundation.
- The WCF is a distributed technology. Using this technology we can implement SOA (Service Oriented Architecture) programming.
- SOA programming provides communication between heterogeneous applications.
- Applications that are developed using different technologies or different programming languages are known as heterogeneous applications.
WPF:
- The WPF stands for windows presentation foundation.
- WPF is a .NET technology using this technology we can create 2D, 3D, graphics, animations for windows application.
- Using this technology we can also create our own audio/video players and also implement gaming applications.
LINQ:
- LINQ stands for Language Integrated Query.
- It is query-writing Technology.
- LINQ offers to write queries in the programming code itself.
- This concept is introduced in .NET framework 3.5
- LINQ queries applying in database data and non-database data also.
What is Visual Studio?
Visual Studio is a Microsoft IDE tool that is needed to develop applications with the .NET framework. The IDE integrates 3 features
- Editor
- Compiler
- Interpreter
What is .Net?
- .NET is a programming framework created by Microsoft that developers can use to create applications more easily. The framework provides libraries commonly used by developers. The .NET Base Class Libraries (BCL) serves that purpose.
- The .NET provides language interoperability across several programming languages. Programs are written for .NET Framework execute in a software environment called Common Language Runtime (CLR).
- CLR is the foundation of the .NET framework which provides services like safety, memory management, garbage collection, and exception handling.
- CLR manages the execution of code. The code that is managed by CLR is called managed code. Unmanaged code does not get managed by CLR. CLR’s interoperability helps to interact between managed and unmanaged code.
- Common Language Specification (CLS) and Common Type System (CTS) as part of CLR. CTS is responsible for interpreting data types into a common format. CLS provides the ability of code to interact with code that is written with a different programming language.
What is the Just-In-Time (JIT) compilation?
The MSIL is the language that all of the .NET languages compile down to. After they are in this intermediate language, a process called Just-In-Time compilation occurs when resources are used from our application at runtime.
What is metadata?
Metadata describes every type and member defined in our code in a Multilanguage form. Metadata stores the following information.
- Description of assembly.
- Identity (name, version, culture, public key).
- The types that are exported
- Other assemblies that this assembly depends on.
- Security permissions needed to run.
What is an assembly?
Assemblies are the building block of .NET framework applications; they form the fundamental unit of deployment, version control, reuse, and activation scoping and security permissions.
What are the differences between managed code and unmanaged code?
This is one of the frequently asked C# Interview Questions and Answers. Let us discuss the difference between them.
Managed code/methods:
Machine instructions are in MSIL format and located in assemblies will be executed by the CLR will have the following advantages
- Memory management to prevent memory leaks in program code.
- Thread execution
- Code safety verification
- Compilation.
Unmanaged code/ methods:
The Unmanaged codes are the instructions that are targeted for specific platforms. Unmanaged code will exist in any of the formats.
- COM/COM+ components
- Win 32 Dlls/system DLLs
- As these codes are in native formats of OS, these instructions will be executed faster compared with JIT compilation and execution of managed code.
What is C#?
C# is an object-oriented typesafe and managed language that is compiled by the .Net framework to generate Microsoft Intermediate Language.
What is the difference between an EXE and a DLL?
This is one of the frequently asked C# Interview Questions and Answers. Let us understand the difference between Exe and DLL. EXE is an executable file and can run by itself as an application whereas DLL is usually consumed by an EXE or by another DLL and we cannot run or execute DLL directly.
For example in .NET compiling a Console Application or a Windows Application generates EXE, whereas compiling a Class Library Project or an ASP.NET web application generates DLL. In the .NET framework, both EXE and DLL are called assemblies.
A DLL can be reused in the application whereas an exe file can never be reused in an application. EXE stands for executable, and DLL stands for Dynamic Link Library
What’s the difference between IEnumerable<T> and List<T>?
- IEnumerable is an interface, whereas List is one specific implementation of IEnumerable. A list is a class.
- FOR-EACH loop is the only possible way to iterate through a collection of IEnumerable whereas List can be iterated using several ways. The list can also be indexed by an int index. The element of a list collection can be added to and removed from and have items inserted at a particular index but these are not possible with a collection of type IEnumerable.
- IEnumerable doesn’t allow random access, whereas List does allow random access using the integral index.
- In general, from a performance standpoint, iterating through IEnumerable is much faster than iterating through a List.
Why is class an abstract data type?
A Class is an Abstract Data Type because it specifies what data members and member functions (methods) contain in it (class), but it does not provide information on how those are implemented. That makes Class Abstract and Class is User Defined DataType. So, it’s an Abstract Data Type
What are the new features introduced in C# 7?
This is a very commonly asked C# interview question. This question is basically asked to check if you are passionate about catching up with the latest technological advancements. The list below shows the new features that are introduced in C# 7. Let’s have a look at the new features that are introduced as part of C# 7
- Out variables
- Pattern matching
- Digit Separators
- Tuples
- Deconstruction (Splitting Tuples)
- Local functions
- Literal improvements
- Ref returns and locals
- Generalized async return types
- More expression-bodied members
- Throw expressions
- Discards
- Async main
- Default literal expressions
- Inferred tuple element names
Why should you override the ToString() method?
This C# Interview Question is one of the most frequently asked .NET questions. All types in .Net inherit from the System.Object class directly or indirectly. Because of this inheritance, every type in .Net inherits the ToString() method from System.Object class. To understand this better, please have a look at the example.
In the above example Number.ToString() method will correctly give the string representation of int 10, when we call the ToString() method. If we have any user-defined class like Customer class as shown in the below example and when we call the ToString() method the output does not make any sense i.e. in the output you simple get the class name.
But what if we want to print the first name and last name of the customer when we call the toString method on the customer object. Then we need to override the ToString() method, which is inherited from the System.Object class. The code sample below shows how to override the ToString() method in a class, that would give the output what we want.
What is the difference between string keyword and System.String class?
Actually there is no difference. The string keyword is an alias for System.String class. Therefore System.String and string keywords both are the same, and we can use whichever naming convention we prefer. The String class provides many methods for safely creating, manipulating, and comparing strings.
Are string objects mutable or immutable?
String objects are immutable.
What do you mean by String objects are immutable?
This C# Interview Question is frequently asked .NET Interviews. String objects are immutable means they cannot be changed once they are created. All of the String methods and C# operators that appear to modify a string actually return the results in a new string object. In the following example, when the contents of s1 and s2 are concatenated to form a single string, the two original strings are unmodified. The += operator creates a new string that contains the combined contents. That new object is assigned to the variable s1, and the original object that was assigned to s1 is released for garbage collection because no other variable holds a reference to it.
What will be the output of the following code?
The output of the above code is “Hello” and not “Hello C#”. This is because, if you create a reference to a string, and then “modify” the original string, the reference will continue to point to the original object instead of the new object that was created when the string was modified.
What is a verbatim string literal and why do we use it?
The “@” symbol is the verbatim string literal. Use verbatim strings for convenience and better readability when the string text contains backslash characters, for example in file paths. Because verbatim strings preserve newline characters as part of the string text, they can be used to initialize multiline strings. Use double quotation marks to embed a quotation mark inside a verbatim string. The following example shows some common uses for verbatim strings:
Will the following code compile and run?
string str = null;
Console.WriteLine(str.Length);
The above code will compile but at runtime System.NullReferenceException will be thrown.
How do you create empty strings in C#?
Using string.empty as shown in the example below.
string EmptyString = string.empty;
What is the difference between System.Text.StringBuilder and System.String?
This is one of the frequently asked C#.NET Interview Questions. Objects of type StringBuilder are mutable whereas objects of type System.String is immutable. As StringBuilder objects are mutable, they offer better performance than string objects of type System.String. The StringBuilder class is present in System.Text namespace where String class is present in System namespace.
How do you determine whether a String represents a numeric value?
To determine whether a String represents a numeric value, we can use the TryParse method as shown in the example below. If the string contains non-numeric characters or the numeric value is too large or too small for the particular type you have specified, TryParse returns false and sets the out parameter to zero. Otherwise, it returns true and sets the out parameter to the numeric value of the string.
What is the difference between int.Parse and int.TryParse methods?
The parse method throws an exception if the string you are trying to parse is not a valid number whereas TryParse returns false and does not throw an exception if parsing fails. Hence TryParse is more efficient than Parse.
What are Properties in C#? Explain with an example?
It is one of the frequently asked C# Interview Questions. Properties in C# are class members that provide a flexible mechanism to read, write, or compute the values of private fields. Properties can be used as if they are public data members, but they are actually special methods called accessors. This enables data to be accessed easily and still helps promote the safety and flexibility of methods.
In the example below _firstName and _lastName are private string variables that are accessible only inside the Customer class. _firstName and _lastName are exposed using FirstName and LastName public properties respectively. The get property accessor is used to return the property value, and a set accessor is used to assign a new value. These accessors can have different access levels. The value keyword is used to define the value being assigned by the set accessor. The FullName property computes the full name of the customer. The FullName property is read-only because it has only the get accessor. Properties that do not implement a set accessor are read-only.
The code block for the get accessor is executed when the property is read and the code block for the set accessor is executed when the property is assigned a new value.
What are the different types of properties available in C#?
In C#, there are three types of Properties available. They are shown in the following image.
- Read-Only Properties: Properties without a set accessor are considered read-only. In our example, FullName is a read-only property.
- Write Only Properties: Properties without a get accessor are considered write-only. In our example, the Country is a write-only property.
- Read Write Properties: Properties with both a get and set accessor are considered read-write properties. In our example, FirstName and LastName are read-write properties.
What are the advantages of using properties in C#?
- Properties can validate data before allowing a change.
- It can transparently expose data on a class where that data is actually retrieved from some other source such as a database.
- Properties can take action when data is changed, such as raising an event or changing the value of other fields.
What is a static property? Give an example?
A property that is marked with a static keyword is considered as a static property. This makes the property available to callers at any time, even if no instance of the class exists. In the example below PI is a static property.
What is Virtual Property in C#? Give an example?
This is one of the most frequently asked C#.NET Interview Questions. A property that is marked with a virtual keyword is considered virtual property. Virtual properties enable derived classes to override the property behavior by using the override keyword. In the example below FullName is a virtual property in the Customer class. BankCustomer class inherits from Customer class and overrides the FullName virtual property. In the output, you can see the overridden implementation. A property overriding a virtual property can also be sealed, specifying that for derived classes it is no longer virtual.
What is an Abstract Property in C#? Give an example?
A property that is marked with the abstract keyword is considered abstract property. An abstract property should not have any implementation in the class. The derived classes must write their own implementation. In the example below FullName property is abstract in the Customer class. BankCustomer class overrides the inherited abstract FullName property with its own implementation.
Can you use virtual, override, or abstract keywords on an accessor of a static property?
No, it is a compile-time error to use a virtual, abstract, or override keywords on an accessor of a static property.
Is C# a strongly-typed language?
Yes
What are the 2 broad classifications of data types available in C#?
- Built-in data types.
- User-defined data types.
Give some examples of built-in data types in C#?
- Int
- Float
- Bool
How do you create user-defined data types in C#?
You use the struct, class, interface, and enum constructs to create your own custom types. The .NET Framework class library itself is a collection of custom types provided by Microsoft that you can use in your own applications.
Difference between int and Int32 in C#
This is one of the frequently asked C# Interview Questions and Answers. Int32 and int are synonymous, both of them allow us to create a 32-bit integer. int is shorthand notation (alias) for Int32. When declaring an integer in a c# program most of us prefer using int over Int32. Whether we use int or Int32 to create an integer, the behavior is identical.
I think the only place where Int32 is not allowed is when creating an enum. The following code will raise a compiler error stating – Type byte, sbyte, short, ushort, int, uint, long, or ulong expected.
The following code will compile just fine
I can think of only the following minor differences between int and Int32
- One of the differences is in readability. When we use Int32, we are being explicit about the size of the variable.
- To use Int32, either we need to use using System declaration or specify the fully qualified name (System.Int32) whereas with int it is not required.
What are the 2 types of data types available in C#?
- Value Types
- Reference Types
If you define a user-defined data type by using the struct keyword, Is it a value type or reference type?
Value Type
If you define a user-defined data type by using the class keyword, Is it a value type or reference type?
Reference type
Are Value types sealed?
Yes, Value types are sealed.
What is the base class from which all value types are derived?
System.ValueType
Give examples of value types?
- Enum
- Struct
Give examples for reference types?
- Class
- Delegate
- Array
- Interface
What are the differences between value types and reference types?
This is one of the frequently asked C# Interview Questions and Answers. Value types are stored on the stack whereas reference types are stored on the managed heap. The Value type variables directly contain their values whereas reference variables hold only a reference to the location of the object that is created on the managed heap.
There is no heap allocation or garbage collection overhead for value-type variables. As reference types are stored on the managed heap, they have the overhead of object allocation and garbage collection.
Value Types cannot inherit from another class or struct. Value types can only inherit from interfaces. Reference types can inherit from another class or interface.
My understanding is that just because structs inherit from System.ValueType, they cannot inherit from another class, because we cannot do multiple class inheritance.
Structs can inherit from System.ValueType class but cannot be inherited by any other types like Structs or Class. In other words, Structs are like Sealed classes that cannot be inherited.
What do you mean by casting a data type?
Converting a variable of one data type to another data type is called casting. This is also called data type conversion.
What are the 2 kinds of data type conversions available in C#?
Implicit conversions: No special syntax is required because the conversion is typesafe and no data will be lost. Examples include conversions from smaller to larger integral types and conversions from derived classes to base classes.
Explicit conversions: Explicit conversions require a cast operator. The source and destination variables are compatible, but there is a risk of data loss because the type of the destination variable is a smaller size than (or is a base class of) the source variable.
What is the difference between an implicit conversion and an explicit conversion?
Explicit conversions require a cast operator whereas an implicit conversion is done automatically. The Explicit conversion can lead to data loss whereas with implicit conversions there is no data loss.
What type of data type conversion happens when the compiler encounters the following code?
ChildClass CC = new ChildClass();
ParentClass PC = new ParentClass();
Implicit Conversion: For reference types, an implicit conversion always exists from a class to any one of its direct or indirect base classes or interfaces. No special syntax is necessary because a derived class always contains all the members of a base class.
Will the following code compile?
double d = 9999.11;
int i = d;
No, the above code will not compile. Double is a larger data type than the integer. An implicit conversion is not done automatically because there is a data loss. Hence we have to use explicit conversion as shown below.
double d = 9999.11;
int i = (int)d; //Cast double to int.
If you want to convert a base type to a derived type, what type of conversion do you use?
Explicit conversion as follows. Create a new derived type.
Car C1 = new Car();
Implicit conversion to the base type is safe.
Vehicle V = C1;
Explicit conversion is required to cast back to the derived type. The code below will compile but throw an exception at runtime if the right-side object is not a Car object.
Car C2 = (Car) V;
What operators can be used to cast from one reference type to another without the risk of throwing an exception?
The is and as operators can be used to cast from one reference type to another without the risk of throwing an exception.
If casting fails what type of exception is thrown?
InvalidCastException
What is the difference between int.Parse and int.TryParse methods?
This is one of the frequently asked C# Interview Questions and Answers. The parse method throws an exception if the string you are trying to parse is not a valid number whereas TryParse returns false and does not throw an exception if parsing fails. Hence TryParse is more efficient than Parse.
What are Boxing and Unboxing?
Boxing – Converting a value type to reference type is called boxing. An example is shown below.
int i = 101;
object obj = (object)i; // Boxing
Unboxing – Converting a reference type to a value type is called unboxing. An example is shown below.
obj = 101;
i = (int)obj; // Unboxing
Is boxing an implicit conversion?
Yes, boxing happens implicitly.
Is unboxing an implicit conversion?
No, unboxing is an explicit conversion.
What happens during the process of boxing?
This is one of the frequently asked C# Interview Questions and Answers. Boxing is used to store value types in the garbage-collected heap. Boxing is an implicit conversion of a value type to the type object or to any interface type implemented by this value type. Boxing a value type allocates an object instance on the heap and copies the value into the new object. Due to this boxing and unboxing can have a performance impact.
What are Access Modifiers in C#?
This is one of the frequently asked C# Interview Questions and Answers. In C# there are 5 different types of Access Modifiers.
- Public: The public type or member can be accessed by any other code in the same assembly or another assembly that references it.
- Private: The type or member can only be accessed by code in the same class or struct.
- Protected: The type or member can only be accessed by code in the same class or struct, or in a derived class.
- Internal: The type or member can be accessed by any code in the same assembly, but not from another assembly.
- Protected Internal: The type or member can be accessed by any code in the same assembly, or by any derived class in another assembly.
What are Access Modifiers used for?
Access Modifiers are used to control the accessibility of types and members within the types.
Can we use all access modifiers for all types?
No, not all access modifiers can be used by all types of members in all contexts, and in some cases, the accessibility of a type member is constrained by the accessibility of its containing type.
Can derived classes have greater accessibility than their base types?
No, Derived classes cannot have greater accessibility than their base types. For example, the following code is illegal.
When we compile the above code an error will be generated stating “Inconsistent accessibility: base class InternalBaseClass is less accessible than class PublicDerivedClass“. To make this simple, you cannot have a public class PublicDerivedClass that derives from an internal class InternalBaseClass. If this were allowed, it would have the effect of making public, because all protected or internal members of A are accessible from the derived class.
Is the following code legal in C#?
No, a compile-time error will be generated stating “Namespace elements cannot be explicitly declared as private, protected, or protected internal“
Can you declare struct members as protected?
No, struct members cannot be declared protected. This is because structs do not support inheritance.
Can the accessibility of a type member be greater than the accessibility of its containing type?
No, the accessibility of a type member can never be greater than the accessibility of its containing type. For example, a public method declared in an internal class has only internal accessibility.
Can destructors have access modifiers?
No, destructors cannot have access modifiers.
What does protected internal access modifiers mean?
The protected internal access means protected OR internal, not protected, AND internal. In simple terms, a protected internal member is accessible from any class in the same assembly, including derived classes. To limit access to only derived classes in the same assembly, declare the class itself internal, and declare its members as protected.
What is the default access modifier for a class, struct, and an interface declared directly with a namespace?
internal
Will the following code compile in C#?
No, you cannot specify the access modifier for an interface member. Interface members are always public.
Can you specify an access modifier for an enumeration?
Enumeration members are always public, and no access modifiers can be specified.
In the next article, I am going to discuss Interface and Inheritance related interview questions and answers in C#. Here, in this article, I try to explain the most frequently asked Basic C# Interview Questions and Answers. I hope you enjoy this Basic C#.NET Interview Questions and Answers article.
Leave a Comment