Share 125 basic C# interview questions and answers

怪我咯
Release: 2017-04-07 10:36:29
Original
2562 people have browsed it

The following is a list of 125 basic C# interview questions and answers. These interview questions are simple, straightforward, and cover the most basic concepts of C#, most of which are related to object-oriented concepts. So if you are preparing for C# interview, I suggest you must master these 125 basic C# interview questions and answers to review your C# concepts. So now let’s take a look at this list of 125 essential C# interview questions and answers. 1. What is C#?

C# (pronounced "C sharp") is a simple, different from traditional, object-oriented, type-safe

programming language

. C and C++ programmers will quickly become familiar with it. The highly productive Rapid Application Development (RAD) language is combined in C#. 2. What are the annotation types in C#?

There are three annotation types in C#.

Single line (//)

Multiple lines (/* */)
Page/XML comments (///).

3. What are the

namespaces

used in C#.NET? A namespace is a logical grouping of types.

using System;

using System.Collections.Generic;
using System.Windows.Forms;

4. What are the characteristics of C#?

C# has the following characteristics:

Simple

Type safety

Flexible
Object-oriented
Compatible
Persistence
Interoperability
Different from traditional

5. What are the different categories of inheritance?

Four types of inheritance in object-oriented programming:

Single inheritance: including a base class and a derived class.

Multi-level inheritance (Hierarchical inheritance): includes a base class and derived classes that inherit from the same base class.

Multilevel inheritance: Includes classes derived from a derived class.

Multiple inheritance: includes multiple base classes and a derived class.

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

It is necessary to understand some concepts that are widely used in object-oriented programming. They include:

Objects

Classes

Data abstraction and encapsulation
Inheritance
Polymorphism
Dynamic binding
Information transfer.

7. Can you inherit multiple

interfaces

? OK. In C# it is possible to inherit multiple interfaces.

8. What is inheritance?

Inheritance is a new class derived from an existing class.

9. Define scope? Define scope?

Scope refers to the area in the code where a

variable

can be accessed. 10. What is the difference between public, static and void?

public: The keyword public is an access modifier, used to tell the C# compiler that the main (Main) method can be called by anyone.

static: The keyword static indicates that the main method is a global method and can be accessed without a class instance. The compiler stores the address of the method as the entry point and uses this information to start executing it before any objects are created.

void: The keyword void is a type modifier indicating that the main (Main) method does not return any value.

11. What are the modifiers in C#?

Abstract

Sealed

Virtual
Const
Event
Extern
Override
Readonly
Static
New

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

The access modifier in C# is:

public

protect

private
internal
internal protect

13. What is boxing And unboxing?

The variable value type is implicitly converted to a reference type and becomes boxed, for example,

type conversion

from integer to object. Conversion of reference type variables back to value types becomes unboxing.

14. What is the object?

Objects are instances of classes. Objects are created using the new operation. A class

creates an object

in memory that will contain information about the values ​​and behavior (or methods) of a specific object. 15. What types of

arrays

are there in C#?

One-dimensional array

(Single-Dimensional)Multidimensional array
(Multidimensional)Jagged arrays.
16. What is the difference between objects and instances?

An instance of a user-defined type is called an object. We can instantiate many objects from a class.

Objects are instances of classes.

17. Define destructors?Definition

Destructor

?

The destructor is called when the class object goes out of scope or is explicitly deleted. The destructor, as the name suggests, is used to destroy the object created by the constructor. Just like the constructor, the destructor is a class member method. The method name is the same as the class name, but starts with a tilde.

18. How to use enumerationdata type?

The enumeration type is another user-defined type that provides a way to connect names to numbers, thereby improving the understandability of the code. The enum keyword automatically enumerates a group of words, assigning them the values ​​0, 1, 2 and so on.

19. Define a constructor?

The constructor is a member method with the same name as its class. The constructor is called whenever an object of its associated class is created. It is called a constructor because it constructs the values ​​of the data members of the class.

20. What is encapsulation?

Packaging data and functionality into a unit (called a class) is called encapsulation. Encapsulation contains and hides object information, such as internal data structures and code.

21. Does C# support multiple inheritance?

Not supported, it's impossible. Supports multi-level inheritance.

22. What is ENUM?

Enum is used to define constants.

23. What is the data set?

Dataset (DataSet) is an in-memory representation of data loaded from any data source.

24. What is the difference between private and public keywords?

Private: The keyword private is the default access level and the most restrictive of all other access levels. It gives minimal permissions to a type or type members. Private members can only be accessed within the class body in which they are declared.

Public: The keyword public is the most free of all access levels, without any access restrictions. Public members can be accessed not only from the outside, but also from the inside, and can freely access any member defined inside or outside the class body.

25. Define polymorphism?

Polymorphism means one name, many forms. It allows us to define more than one method with the same name in a program. It lets us overload operations so that they behave differently on different instances.

26. What is a jagged array?

A jagged array is an array whose elements are arrays.

The dimensions and sizes of the elements of a jagged array can be different.

Jagged arrays are sometimes called "arrays of arrays".

27. What is an abstract base class?

Abstract class is a class designed specifically to serve as a base class. Abstract classes also have at least one pure virtual method.

28. What is the difference between method overriding and method overloading?

When you override a method, you change the behavior of the method in the derived class. An overloaded method simply involves another method with the same name in the class.

29. What is the difference between ref and out parameters?

The parameters passed to the ref parameter must be initialized first. In contrast, for out parameters, no explicit initialization is required before the parameter is passed to the out parameter.

30. How to use using statement in C#?

The using statement usually acquires a resource, executes the statement, and then releases the resource.

31. What is serialization?

Serialization (Serialization) is the process of converting objects into byte streams.

Deserialization (De-serialization) is the reverse process of creating an object from a byte stream .

Serialization/deserialization is often used to pass objects.

32. What is the difference between structure and class?

Structures are value types and classes are reference types.

Structures cannot have constructors and destructors.

A class can have both a constructor and a destructor.

Structures do not support inheritance, but classes support inheritance.

33. What is the difference between a class and an interface?

Class (Class) is the logical representation of an object. It is the definition of a data collection and related sub-processes.

Interface (Interface) is also a class that contains methods without any method body definition. Classes do not support multiple inheritance, but interfaces do.

34. What is delegation?

A delegate is a type-safe, object-oriented implementation of a function pointer, and is used in many situations where a component needs to call back to the component that uses it.

35. What is authentication and authorization?

Authentication is the process of identifying a user. Authentication uses certificates (username and password) to identify/verify users.

Authorization is performed after authentication. Authorization is the process of granting access based on these user identities.

Authorization allows users to access specific resources.

36. What is a base class?

The class declaration can specify the base class by adding a colon and the base class name to the class name. Omitting a base class specification is equivalent to deriving from object class.

37. Can "this" be used in static methods?

No, 'This' cannot be used in static methods. Only static variables/methods can be used in static methods.

38. What is the difference between constants, readonly and static?

Constants: The value cannot be changed.

Read-only: The value is initialized only once in the constructor of the class.

Static: The value can be initialized once.

39. What statement types are supported in C#?

The several different statement types supported by C# are

Block Statement
Declaration Statement
Expression Statement
Selection Statement
Iteration Statement
Jump Statement
Exception handling statement
Checked and unchecked
Lock statement

40. What is an interface class?

It is an abstract class, and all public abstract methods must be implemented in its inherited class.

41. What are value types and reference types?

Value types are stored on the stack.
For example: bool, byte, chat, decimal, double, enum, float, int, long, sbyte, short, strut, uint, ulong, ushort.

Reference types are stored in the managed heap.
For example: class, delegate, interface, object, string.

42. What is the difference between the keyword string and the System.String class?

The keyword string is an alias of the System.String class. So, System.String is the same as the keyword string, and you can use whatever naming convention you like. The String class provides many methods for safely creating, manipulating, and comparing strings.

43. What are the two data types provided in C#?

Value type
Reference type

44. What types of cache are there?

There are three types of cache:

Output Caching (Output Caching): stores the response information of the asp.net page.

Fragment Caching: Only cache/store part of the page content (user control).

Data Caching: Cache objects programmatically for performance.

45. What is the difference between custom controls and user controls?

Custom controls are compiled codes (Dlls) that are easy to use but difficult to create and can be placed in the toolbox. Controls used by dragging.

Properties can be intuitively specified at design time. It can be used by multiple applications (if shared Dlls), even if it is private, it can be copied to the bin directory of the web application, added for reference and used. Typically used to provide common functionality to independent consumer applications.

User controls and ASP include files are easily created and cannot be placed in a box to drag and drop them. User controls are shared between individual application files.

46. What is a method?

Methods are members executed by objects or classes to implement calculations or operations. Static methods are accessed through classes. Instance methods are accessed through instances of the class.

47. What is a domain?

Domains are variables related to classes or instances of classes.

48. What is event?

Events are members that enable a class or object to provide notifications. Event declarations are like domain declarations, except that the declaration contains the event keyword and the type must be a delegate type.

49.What are texts and their types?

Text is the value constant that the program assigns to the variable. Several text types supported by C# are

Integer literals
Real literals
Boolean values
Single character literals
Characters String literals
Backslash character literals

50. What is the difference between value types and reference types?

The value type is stored on the stack and is the value of one variable assigned to another variable.

Reference types are stored on the managed heap and are assignments between two reference variables.

51. What are the features of C#?

C# is a simple yet powerful programming language for writing enterprise applications.
It is a mixture of C++ and VB. It retains many C++ features such as statements, expressions and operators and combines them with the productivity of VB.

C# helps developers easily build network services and can access the Internet through any language and any platform.

C# helps developers complete development with less code, resulting in fewer errors in the code.

C# introduced considerable improvements and innovations in areas such as type safety, version control, events, and garbage collection.

52. What are the types of errors?

Syntax error
Logic error
Runtime error

53. What is the difference between break and continue statements?

The break statement is used to terminate the current closed loop or the conditional statement in which it is located. We have used the break statement to jump out of the switch statement.

Thecontinue statement is used to change the order of execution. As opposed to breaking out of a loop like the break statement, the continue statement stops the current iteration and only returns control to the top of the loop.

54. Define namespace?

Namespaces are called containers and are used to organize hierarchical .NET classes.

55. What is a code group?

A code group is a group of suites that share a security context.

56. What is a sealed class in C#?

The sealed modifier is used to prevent derivation from a class. A compile-time error occurs if a sealed class is specified as a base class for another class.

57. What is the difference between static methods and instance methods?

Methods declared with the static modifier are static methods. Static methods do not operate on specific instances and can only be accessed by static members.

Methods not declared with the static modifier are instance methods. Instance methods operate on a specific instance and can be accessed by static and instance members. The instance on which the instance method is called can be accessed explicitly like this. It is wrong to call this in a static method.

58. What types of variables are there in C#?

The different variable types in C# are:

static variables
instance variables
value parameters
reference parameters ( reference parameters)
array elements
output parameters
local variables

59. What does method overloading mean?

Method overloading allows multiple methods in the same class to have the same name, as long as they have unique signatures. When compiling a call to an overloaded method, the compiler uses overload resolution to determine which method to call.

60. What are parameters?

Parameters are used to pass values ​​or variable references to methods. The parameters of the method get their actual values ​​from the parameters specified when the method was called. There are four kinds of parameters: value parameters, reference parameters, output parameters and parameter arrays.

61. Is C# an object-oriented language?

Yes, C# is an object-oriented language like traditional Java and C++.

62. What is the difference between Array and Arraylist?

Arrays are collections of the same type. The size of an array is fixed when it is declared. A linked list is similar to an array, but it does not have a fixed size.

63. What are the special operators in C#?

C# supports some special operators.

is (relational operator)
as (relational operator)
typeof (type operator)
sizeof (size operator, used to get the size of an unmanaged class)
new (object operator)
.dot (member access operator)
checked (overflow check)
unchecked? (prevent overflow check)

64. The meaning of operators in C# What is it?

Operators are members that define the connotation of applying specific operation expressions to class instances. Three types of operators can be defined: unary operators, binary operators and conversion operators. All operators must be declared public and static.

65. What is type parameterization?

Type parameterization is the parameterization of a type on another value or type.

66. What are the characteristics of abstract classes?

Abstract classes cannot be made powerful. It is wrong to use the new operator on abstract classes.

Abstract classes are allowed (but not required) to contain abstract methods and entries.

Abstract classes cannot use the scaled modifier.

67. How to use abstract keyword?

The modifier abstract is a keyword used for classes to indicate that the class itself cannot directly have instances or objects, and it can only be a "base class" for other classes.

68. How to use goto statement?

The goto statement is still included in the C# language. This goto can be used to jump from the inside of a loop to the outside. But jumping into the loop from outside the loop is not allowed.

69. What is the difference between console applications and window applications?

Console application, designed to run from the command line without a user interface.
Window applications are designed to be executed on the user's desktop through a user interface.

70. How to use return statement?

The return statement is related to the program (method or function). When the return statement is executed, the system transfers control from the called program to the calling program. The return statement is used for two purposes:

Immediately return to the caller of the currently executed code

Return some value to the caller of the currently executed code.

71. What is the difference between Array and LinkedList?

Arrays are simple sequences of numbers that don't care about the position of each other's elements. Their positions are independent of each other. Adding, deleting or modifying any array element is very easy. Compared to an array, a linked list is a complex sequence of numbers.

72. Does C# have a throws clause?

No, unlike Java, C# does not require developers to specify the exceptions that methods can throw.

73. Does C# support a variable number of parameters?

Yes, use the params keyword. The parameter is specified as a parameter list of a specific type.

74. Can private virtual methods be overridden?

No, private methods cannot be accessed outside the class.

75. What is multicast delegation?

Each delegate object maintains a reference to a separate method. However, it is possible for a delegate object to hold references to multiple methods and call them. Such delegate objects become multicast delegates or composite delegates.

76. What are the unique features of C#?

XML document.

77. Is using exceptions recommended in C#?

Yes, exceptions are the recommended error handling mechanism in the .NET Framework.

78. What does the break statement do in the switch statement?

The break statement terminates the loop in which it is located. It also changes the flow of program execution.

In the switch statement, the break statement is used at the end of a case statement. The break statement is mandatory in C# and prevents one case statement from flowing into another case statement.

79. Is C# object oriented? Is C# object oriented?

Yes, C# is an object-oriented language like traditional Java and C++.

80. What is intelligent navigation?

Because the server-side verification and the page are refreshed, the cursor position remains unchanged when the page is refreshed.

81. What is the difference between CONST and READONLY?

are all for defining constant values. A const field can only be initialized when the field is declared. Readonly fields can be defined at declaration time or in the constructor.

82. Does C# have a throws clause?

No, unlike Java, C# does not require (or even allows) developers to specify exceptions that methods can throw.

83. What are the different ways methods can be overloaded?

Different parameter types, different number of parameters, and different parameter order.

84. Does the event have a return value?

No, the event has no return type.

85. What is the event?

An event is an action performed based on another program method.

Events are delegate type class members used by objects or classes to notify other objects of events that have occurred.

Events can be declared through the event keyword.

86. What is an identifier?

Identifier is the name used to uniquely identify various entities in the program.

87. What are the different text types in C#?

Boolean values: True and False are Boolean types, which are mapped to true and false states respectively.

Integer: used to write values ​​of types Int, uInt, long and ulong.

Real numbers: used to write values ​​of type float, double and decimal.

character: represents a single character, usually composed of quoted characters, such as ‘a’.

String: C# supports two types of strings, regular strings and literal strings. A rule string consists of 0 or more characters enclosed in double quotes, such as "116110". A literal string consists of the @ character followed by double-quoted characters, such as @"hello".

Null: represents null type.

88. What is data encapsulation?

Data encapsulation, also known as data hiding, is a mechanism for keeping the implementation details of a class hidden from users. Users can only perform a limited set of operations on a class with hidden members by executing special functions called methods.

89. Can private virtual methods be overridden?

No, private methods cannot be accessed outside the class.

90. What is the main difference between subroutines and functions?

Subprograms do not have return values, but functions do.

91. What is the difference between C# and C++?

C# does not support the #include statement. It only uses using statements.

In C#, class definitions do not use semicolons at the end.

C# does not support multiple inheritance.

Explicit conversion of data types is much safer in C# than in C++.

Switch in C# can also be used for string values.

The behavior of command line parameter arrays is different in C# and C++.

92. What is a nested class?

Nested classes are classes within classes.

A nested class is any class whose declaration occurs inside another class or interface.

93. Can I give static constructor function parameters?

No, static constructors cannot have parameters.

94. In C#, is a string a value type or a reference type?

Strings are objects (reference types).

95. Does C# provide a copy constructor?

No, C# does not provide a copy constructor.

96. Can a class or structure have multiple constructors?

Yes, a class or structure can have multiple constructors. Constructors can be overloaded in C#.

97. Can I create an instance of an interface?

No, you cannot create instances of interfaces.

98. Can an interface contain fields?

No, the interface cannot contain fields.

99. Can a class have a static constructor?

Yes, classes can have static constructors. Static constructors are automatically called immediately before any static fields are accessed, and are typically used to initialize static class members. It is automatically called before the first instance is created or any static members are referenced. Static constructors are called before instance constructors. An example is shown below.

100. What is the main function of delegation in C#?

Delegates are mainly used to define callback methods.

101. What is the difference between shadowing and overriding?

Overriding only redefines the implementation while projection redefines the entire element.

Overriding derived classes can refer to parent class elements through the "ME" keyword, but in projection you can access parent class elements through "MYBASE".

102. Can events use access modifiers?

Yes, you can use access modifiers in events. You can use the portected keyword on an event to allow access only to inherited classes. You can use private to decorate events so that they can only be accessed by objects of the current class.

103. Why use the virtual keyword in the code?

The Virtual keyword in the code is used to define methods and properties that can be overridden in derived classes.

104. What are constructors and destructors?

Constructors and destructors are special methods.

Constructors and destructors are special methods of each class.

Each class has its own constructor and destructor, which are automatically called when a class instance is created or destroyed.

Whenever you access a class, the constructor initializes all class members. Destructors destroy objects when they are no longer needed.

105. How do we suppress the finalize method?

GC.SuppressFinalize().

106. Does C# support a variable number of parameters?

Yes, use the params keyword.

This parameter is specified as a parameter list of a specific type, for example, int. For maximum flexibility, the type can be object.

The standard example of using this method is System.console.writeLine().

107. Which method is used to start a thread?
Start.

108. What are generics?

Generics help us create flexible, strongly typed collections.

Generics basically separate the logic from the data type to maintain better reusability, better maintainability, etc.

109. What are the different types of polymorphism?

There are two types of polymorphism, they are:

Compile-time polymorphism

Run-time polymorphism

110. Compile-time polymorphism What is the difference between polymorphism and runtime polymorphism?

Compile-time polymorphism

Compile-time polymorphism is also called method overloading.

Method overloading refers to having two or more methods with the same name but different signatures.

Run-time polymorphism

Run-time polymorphism is also known as method overriding.

Method rewriting refers to having two or more methods with the same name, containing the same method signature but corresponding to different implementations.

111. Which namespace makes multi-threaded programming in XML feasible?

System.Threading.

112. Can you declare a static block in C#?

No, because C# does not support static blocks, but it supports static methods.

113. Can a method be declared sealed?

Methods cannot be declared sealed in C#. But when we override a method in a derived class, we can define the overridden method as sealed. By having it sealed, we can avoid further overriding of this method.

114. What command is used to implement properties in C#?

The get and set modifiers are used to implement properties in C#.

115. What are static members?

Defined as static members, they can be called directly from the class level rather than from class instances.

116. What is the syntax for inheriting a class in C#?

When a class is derived from another class, the members of the base class become derived members.

The access modifier used to access members of the base class specifies the access status of the base class members in the derived class.

The syntax for inheriting a class from another class in C# is as follows:

class MyNewClass : MyBaseClass

117. What is the basic difference between while loop and do while loop in C#?

The while loop tests its condition at the beginning, which means that if the condition evaluates to true, the enclosing block of statements is executed 0 or more times. The do while loop iterates through the statement block at least once and then checks the condition at the end.

118. What is the main difference between subroutines and functions?

Subprograms do not have return values, but functions do.

119. What is a sealed class in C#?

The sealed modifier is used to prevent derivation from a class. A compile-time error occurs if a sealed class is specified as a base class for another class.

120. What is the difference between a class and an interface?

An abstract class can implement some of its members, but an interface cannot implement any of its members.

Interfaces cannot have fields, but abstract classes can have fields.

An interface can only inherit from another interface and cannot inherit from an abstract class, while an abstract class can inherit from another abstract class or another interface.

A class can inherit multiple interfaces at the same time, but a class cannot inherit multiple classes at the same time.

Members of abstract classes can define access modifiers but interface members cannot define access modifiers.

121. What is the difference between abstract methods and virtual methods?

Abstract methods do not provide implementation and force derived classes to override the method (unless the derived class is also an abstract class), while virtual methods can have implementations and whether to override them in the derived class is optional. Therefore virtual methods can be implemented and provide the option of overriding by derived classes. An abstract method cannot provide an implementation and forces derived classes to override the method.

122. What is a static method?

It is possible to declare a method as static as long as it does not attempt to access any instance data or other instance methods.

123. What is the New modifier?

The new modifier hides members of the base class. C# only supports signature hiding.

124. What are the advantages of get and set properties in C#?

The get property accessor is used to return the property value.

The set attribute accessor is used to set new values.

125. What is the difference between const and readonly?

Const-declared fields cannot use the static modifier, but readonly can use the static modifier.

const fields can only be initialized at declaration time, while readonly can be initialized at declaration time or in the constructor.

The value of the const field is calculated at design time, while the value of readonly is calculated at runtime.

The above is the detailed content of Share 125 basic C# interview questions and answers. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!