1. What is the difference between heap and stack in C#?

Stack: Allocated and released automatically by the compiler. Variables defined in the function body are usually on the stack. Heap: Usually allocated and released by the programmer. Using new, malloc, and other memory allocation functions, the allocation is on the heap. When stored in the stack to manage the storage order, keep the principle of advanced after out, he is a continuous memory domain, the system automatically allocated and maintained; Heap: Is unordered, it is a discontinuous area of memory, which is controlled and released by the user. If the user does not free the memory, it is collected by the garbage collector (GC) when the memory reaches a certain value. Stack memory is not managed by us, nor is it managed by GC. Release the top element as soon as it is used up. The heap needs to be cleaned by GC. When you use a reference type, you typically operate on a pointer rather than on the reference type object itself. But value types operate on themselves

2. What are delegates in C#? Is the event a proxy?

The essence of a delegate is a class that takes one method as an argument to another. Events are instances of delegates, and events are a special kind of delegate. For example, an argument in the onclick event is one such method.

3. What are the features of C# static constructors?

The first constructor to be executed, and only one nonparametric static constructor is allowed in a class: static variable > static constructor > instance variable > instance constructor

4. How to explain CTS, CLS and CLR respectively

CTS: Universal language system. CLS: Common language specification. CLR: Common language runtime. CTS: Common Type System Indicates the Common Type System. Int32, Int16→int, String→ String, Boolean→bool Each language defines its own types, and.NET provides common types through CTS, which are then translated into corresponding ones. The.net type. CLS: Common Language Specification Grammatical differences in different languages. Each language has its own syntax..NET provides a common syntax through CLS, which is then translated into different languages. .net syntax. CLR: Common Language Runtime: GC, JIT, etc. There are different CLRS, such as the server CLR, Linux CLR(Mono), Silverlight CLR(CoreCLR). It acts as an engine that performs IL.

5. What are value and reference types in C#?

Value types: struct, enum, int, float, char, bool, decimal Reference types: class, Delegate, Interface, array, object, string

6. Please explain the similarities and differences between classes and structs in C#.

Classes can be instantiated as a reference type, classes can implement interfaces and single inheritance from other classes, and they can also be used as base types, structs that are allocated on the heap in memory are value types that are not base types, but can implement interfaces that are allocated on the stack in memory.

7. The role of the new keyword

Operator: create object instance modifier: define a method with the same name in a derived class, hide the base class method constraint: generic constraint definition, constrain the generic type that can be used

8. What’s the difference between int

Int? Is a nullable type and the default value can be nullint. The default value is 0int? Is implemented by boxing int as a reference type

9. What is the difference between value passing and reference passing in C#?

In value passing, the system first allocates memory space for the parameter of the called method, and copies the value of the argument to the parameter according to the position one by one. After that, any change in parameter value of the called method will not affect the corresponding argument.

Instead of copying the value of the argument itself and passing it to the parameter, the system passes its reference value (the address value) to the parameter. Therefore, the variable at the address referenced by the parameter is the same as the argument passed, and any changes to the value of the corresponding parameter in the method body will affect the argument passed as a reference.

In short, passing by value does not mean that value parameters are value types, but rather that parameter variables copy the actual parameter variables, that is, one more identical variable is created on the stack. Passing by reference does not. You can use ref and out to determine whether parameters are passed by reference.

10. What is the difference between ref and out parameter passing in C#?

(1) the value specified by ref must be initialized when the function is called, whereas out does not. (2) The value specified by out will empty itself when entering the function, so it must be initialized inside the function. Note that string, as a special reference type, operates as a value type. To pass the result of an assignment to a parameter within a method, use the ref or out keywords.

11. What is boxing and unboxing in C#?

Boxing: To convert a value type to a reference type Unboxing: to convert a reference type to a value type Boxing: to assign an object instance to a value type in the heap and copy the value to a new object. (1) Step 1: Newly allocate managed heap memory (size is the value type instance size plus a method table pointer. (2) Step 2: Copy the instance field of the value type into the newly allocated memory. (3) Step 3: Return the address of the newly allocated object in the managed heap. This address is a reference to the object.

Unboxing: Checks the object instance to make sure it is a boxing value of the given value type. Copy the value from the instance into a value type variable. Explicit casting is not required for packing, but is required for unpacking. int i=0; System.Object obj=i; // This process is boxing! That’s boxing I! int j=(int)obj; // This process is obj unpacking!

12. What is the difference between overload and override in C#?

Override differs from overload. Overloading is the same as the name of the method. Override overrides a function in a base class. Implement polymorphism. Overloading: method names are the same, but parameters or parameter types are different; Overloading is a process-oriented concept. Overrides: Overrides virtual methods in base classes. Rewriting is an object-oriented concept.

13. What does the static keyword do in C#?

Fields and methods that are meaningful to a class are decorated with the static keyword, called static members, via the class name plus the access operator “. Make a visit to; Fields and methods that are meaningful to an instance of a class without the static keyword are called non-static members or instance members. Note: Static fields have only one copy in memory. Non-static fields have one copy in each instance object. Methods, whether static or not, have only one copy in memory, the difference being that they are accessed by class name or instance name.

C# member variables and member functions are static.

They are called constant member variables and constant member functions, also known as class member variables and class member functions. Each is used to reflect the state of the class. For example, a class member variable can be used to count the number of instances of a class, and a class member function is responsible for the counting action. No new

15. The implementation process of indexer in C#, whether can only index by number, please describe

C# can treat objects like arrays by providing indexers. Attributes, in particular, are exposed as a GET or set method for each element. Indexer can not only index number (array subscript), still have some index HASHMAP string, so, generally speaking, the class in the c # indexer is usually only one, is THIS, there are innumerable, but also can be as long as you can the argument list different indexer has nothing to do with the return value, the greatest benefit of the indexer is to make your code to look natural, A more realistic way of thinking. An official Microsoft example: indexer allows instances of classes or structures to be indexed in the same way as arrays. Indexers are similar to attributes, except that their accessors take parameters. In the following example, a generic class (Class SampleCollection) is defined and provided with simple GET and SET accessor methods (as methods to allocate and retrieve values). The Program class creates an instance of this class for storing strings.

What is the difference between abstract class and interface in C#?

Abstract class abstract declares abstract classes abstract methods. A class with abstract methods is an abstract class. An abstract method, which does not contain a body (does not provide an implementation method), must be overridden by an inheritor. Therefore, abstract classes cannot be instantiated and can only be overridden by subclasses through inheritance.

Interface specifies an interface and only provides some method specifications. No implementation is provided in C#8 or C#9. Can not use public, abstract, etc., no field, constant, no constructor

Differences between the two:

1. Interface cannot have a field, whereas abstract class can have a field. 2. Interface cannot have modifiers such as public, whereas abstract class can. 3. Interface can realize multiple inheritance.

17. Sealed class in C#

Sealed, cannot inherit.

String STR =null and string STR =”” and string STR = string.empty

Empty is the equivalent of “”.Empty is a statically read-only field. String STR =null initializes the object and allocates no memory space

19.byte b = ‘a’; byte c = 1; byte d = ‘ab’; Byte e = ‘ah ‘; byte g = 256; There’s something wrong with these variables what’s wrong with them?

How much data can a data type carry? 1byte =8 bits, 1 Chinese =2 bytes, 1 English =1 byte=8 bits so BC is correct, deG is wrong. ‘a’ is a char, a error Java byte range is -128 127, C# a byte is 0 255

20. The difference between String and StringBuilder

Both are reference types, and the StringBuilder on the allocation heap defaults to 16, allowing you to expand the number of characters in the string it encapsulates. Each StringBuffer object has a certain buffer capacity. When the string size does not exceed its capacity, no new capacity is allocated; when the string size exceeds its capacity, it is automatically increased. Stringbuilder is not always better than Strin in performance for simple string concatenation operations because stringBulider object creation also takes a lot of performance. Overusing StringBuilder when string concatenation is low can result in a waste of performance rather than a savings. Stringbuilder is only considered for an unpredictable number of string operations. As you can see from the final analysis, if you have a relatively small number of string concatenations, you won’t see much difference. When Stringbulider is used, it is best to specify an appropriate capacity value, otherwise it is better than the default value to frequently perform memory allocations if the capacity is insufficient

21. What is an extension approach?

In a nutshell, extension methods enable you to “add” methods to existing types without modifying type conditions: conditions that extension methods must satisfy, 1. 2. The type of the first argument is the type to be extended, and the this keyword should be added to identify it as an extension method

  1. What are the characteristics? How to use it?

Properties and attributes are completely different concepts, but they are similar in name. Attribute is a piece of configuration information associated with a target object. In essence, it is a class that provides additional information associated with the target element. This additional information is stored in the DLL metadata, which itself is meaningless. The runtime retrieves additional information in a reflective manner

23. What is an Application Domain?

A boundary established by the common language runtime around objects created within the same application scope (that is, starting at the application entry point, along any sequence of objects activated). Application domains help isolate objects created in one application from objects created in other applications so that runtime behavior is predictable. Multiple application domains can exist in a single process. An application domain can be thought of as a lightweight process. Play a safe role. Small footprint.

24.byte a =255; a+=5; What is the value of a?

The byte value ranges from -2 ^ 8 to 2 ^ 8 -1, -256 to 258. When a+=1, the value of A is 0. When a+=5, the value of A is 0

25. What is the difference between const and readonly?

Can identify a constant. The main differences are as follows: 1. Different initialization positions. Const must be assigned at the same time it is declared; Readonly can be assigned at declaration; 2. Modify objects differently. Const can modify fields of a class as well as local variables; 3. Const is a compile-time constant, which is determined at compile time. Readonly is a runtime constant that is determined at run time. 4. Const is static by default; 5. Const can modify only string or other reference types with a value of null. Readonly can be of any type.

26. What are the values of a and B?

String strTmp = “a1 “;

int a = System.Text.Encoding.Default.GetBytes(strTmp).Length;

int b = strTmp.Length;

A =8 b=5 A letter, a digit, and a Chinese character each contain two bytes

27. The Strings = new String (” xyz “); How many String objects are created?

Two objects, one is “xyz” and the other is the reference object S to “xyz”.

C# can operate directly on memory

Unsafe in unsafe mode, C# can use Pointers to manipulate memory, but not in managed mode. C#NET does not run with Pointers by default

29. What is strong typing and what is weak typing? Which is better? Why is that?

Strong types are data that is typed at compile time and cannot be changed at execution, whereas weak types are typed at execution time. No good or no good, both are good, strong type safety, because it is determined in advance, and efficient. It is generally used in compiled programming languages, such as c++, Java,c#, PASCAL, etc. Weak types are not safe in comparison, and are prone to errors when running, but they are flexible and used in interpreted programming languages, such as javascript, etc

30. What is math.round (11.5) equal to? What is math.round (-11.5)?

Math. Round (11.5) = 12 math.h Round (11.5) = – 12

31. The difference between & and &&

The same value of && and (and) is true only if both sides of the expression are true. Otherwise, if either side is false, the result is false. (PS: It makes no sense when it comes to logic and, which is not what it is)

The difference between the if (loginUser! =null&&string.IsnullOrEmpty(loginuser.username)&& =null&&string.IsnullOrEmpty(loginuser.username) If you change && to &, a NullPointerException will be thrown. (PS: So it makes no sense when it comes to logic &)

Ampersand is used as a bit operation.

Ampers& is a bit operation that returns an int and a logical operation that returns a bool

32. What’s the difference between I ++ and ++ I?

1. I++ is assigned first and then incremented; ++ I is incremented first, then assigned. 2. I =0, I ++=0, ++= 1; Console.WriteLine(++i==i++); Results a true

33. The difference between AS and IS

If the conversion cannot be performed, the AS returns a bit NULL (no new object is generated). The success of the conversion depends on whether the BIT null is used to check type compatibility. The as does not perform a real type conversion. As is more efficient than IS. As requires only one type compatibility check

34. Talk about the difference between final and finally.

Final: Cannot be inherited as a parent. A class cannot declare final and abstract. Finally: Used with the try{}catch{}finally{} structure to perform any cleanup when exception handling.

35. Briefly describe C# member modifiers

Abstract: Indicates that the method or attribute is not implemented.

Const: Specifies that the value of a field or local variable cannot be changed.

Event: Declares an event.

Extern: Indicates that methods are implemented externally.

Override: A new implementation of a member inherited from a base class.

Readonly: Indicates that a field can be assigned only at declaration time and inside the same class.

Static: Indicates that a member belongs to the type itself and not to a specific object.

Virtual: Indicates that the implementation of a method or accessor can be overridden in an inherited class.

36. What are anonymous classes and what are their benefits?

Undefined, nameless classes that can be used once and then discarded. The benefits are simple, casual and temporary.

37. What is a verbatim string

In normal strings, the backslash character is an escape character. In Verbatim Strings, the characters are interpreted by the programmer as they should be. To use verbatim strings, you simply prefix the string with the @ sign.

// Literal string: escape character

var filename = @”c:\temp\newfile.txt”;

Console.WriteLine(filenaame);

// Literal string: multiple lines of text

var multiLine = @”This is a

multiline paragraph.”;

Console.WriteLine(multiLine);

// Non-verbatim string

var escapedFilename = “c:\temp\newfile.txt”;

Console.WriteLine(escapedFilename);

Output result:

c:\temp\newfile.txt

This is a

multiline paragraph.

c: emp

ewfile.txt

The only characters in verbatim strings that are not interpreted verbatim are double quotes. Because double quotation marks are the key character that defines a string, double quotation marks must be escaped to express them in verbatim strings.

var str = @”””I don’t think so””, he said.”;

Console.WriteLine(str);

Output result:

“I don’t think so”, he said.

Interpolation within a string can also be implemented with the $symbol in verbatim strings.

Testing \n 1 2 3

Output result:

Testing \n 1 2 3

38. List the number formatting conversions you know

The “0” and “#” placeholders can be used for filling. “0” means that if the number of digits is not enough, “0” is added. If the decimal part has more digits, it is rounded. The “#” represents a placeholder, which is used to assist the “0” to fill in the space. The following cases:

// description of "0" : placeholder, if possible, to fill bitsCopy the code

Console.WriteLine(string.Format(“{0:000000}”, 1234)); // Result: 001234

/ / description: "#" placeholder, if possible, padding on the Console. WriteLine (the string. Format (" {0: # # # # # #} ", 1234)); / / the result: 1234 Console. WriteLine (the string. Format (" {0: # # # # # 0} ", 1234)); // Result: 01234Copy the code

Console.WriteLine(string.Format(“{0:0#0####}”, 1234)); // Result: 0001234

Format("{0:000.000}", 1234)); // Result: 1234.000 console. WriteLine(string.Format("{0:000.000}", 4321.12543)); Format("{0:0,0}", 1234567)); // Result: 4321.125 // "," Description: dial table console. WriteLine(String. Format("{0:0,0}", 1234567)); // Result: 1,234,567 // "%" Description: Format to percent console. WriteLine(String. Format("{0:0%}", 1234)); Format("{0:#%}", 1234.125)); // Result: 123400% console. WriteLine(String. Format("{0:#%}", 1234.125)); // Result: 123413% console. WriteLine(string.Format("{0:00.00%}", 1234)); // Result: 123400.00% console. WriteLine(string.Format("{0:#.00%}", 1234.125)); // Result: 123412.50%Copy the code

Built-in shortcut letter formatting usage

// E- scientific notation for console.writeline ((25000).toString ("E")); // Result: $// console.writeline ((2.5).toString ("C")); // Result: $// console.writeline ((2.5).toString ("C")); // Result: ¥2.50 // D[length]- Decimal number console. WriteLine((25).toString ("D5")); // result: 00025 // F[precision]- Floating point, reserved decimal number (round) console.writeline ((25).toString ("F2")); // G[digits]- normal, keep valid digits for specified digits, round console.writeline ((2.52).toString ("G2")); Console.WriteLine((2500000).toString ("N")); // Result: 2,500,000.00 // x-hexadecimal, non-integer will generate format exception console.writeline ((255).toString ("X")); / / the resultCopy the code

ToString can also use custom formatting:

Console.WriteLine((15).ToString("000")); // Result: 015 console.writeline ((15).toString ("value is 0")); // Result: value is 15 console. WriteLine((10.456).toString ("0.00")); // Result: 10.46 console. WriteLine((10.456).toString ("00")); // result: 10 console. WriteLine((10.456).toString ("value is 0.0")); // Result: value is 10.5Copy the code

39. String concatenation, string interpolation

Concatenate an array of strings into a string:

var parts = new[] { “Foo”, “Bar”, “Fizz”, “Buzz”};

var joined = string.Join(“, “, parts);

// joined = “Foo, Bar, Fizz, Buzz”

There are four ways to achieve the same string concatenation:

string first = “Hello”;

stringsecond = “World”;

string foo = first + ” ” + second;

string foo = string.Concat(first, ” “, second);

string foo = string.Format(“{0} {1}”, firstname, lastname);

string foo = $”{firstname} {lastname}”;

String interpolation

var name = “World”;

var str =$"Hello, {name}!" ;Copy the code

// str = “Hello, World!”

Date formatting

var date = DateTime.Now;

Var STR = $”Today is {date: yyyY-MM-DD}!” ;

Padding:

var number = 42;

Var STR = $"The answer to life, The universe and everything is {number,5}.";Copy the code

// STR = “The answer to life, The universe and everything is __42.”

Var STR = $"The answer to life, The universe and everything is ${number,-5}."; // str = "The answer to life, the universe and everything is 42___."Copy the code

Combined with built-in shortcut letter formatting:

Var amount = 2.5;

      var str = $"It costs {amount:C}";
Copy the code

// str = “¥2.50”

      var number = 42;

      var str = $"The answer to life, the universe and everything is {number,5:f1}.";

      // str = "The answer to life, the universe and everything is ___42.1"
Copy the code

What is a virtual function? What is an abstract function?

Virtual function: an unimplemented function that can be inherited and overwritten by subclasses. Abstract function: a function that specifies that its non-virtual subclasses must be implemented and must be overridden.

41. What is a WebService?

A: Web Services are network-based, distributed, modular components that perform specific tasks and comply with specific technical specifications that enable Web services to interoperate with other compatible components.

42. What are common objects in ADO.NET?

Connection: enables the Connection between the program and the database. You cannot get data from a database without opening it with a connection object. The difference between Close and Dispose can be opened after Close, but Dispose cannot be used again.

Command: the Command is used to issue commands to the database, such as querying, adding, modifying, and deleting data, and invoking stored procedures in the database. This object is schema on the Connection object, that is, the Command: object is connected to the data source by the Connection object.

DataAdapter: Mainly performs data transmission between data source and DataSet. It can issue commands through the Command object and put the obtained data into the DataSet object. This object is built on top of the Command object and provides many functions used by the DataSet.

DataSet: This object can be regarded as a Cache, which can store the data queried from the database, or even display the entire database. The DataSet is stored in memory. The DataSet can not only store multiple tables, but also obtain some data Table structures, such as primary keys, through the DataAdapter object, and record the association between data tables. DataSet object can be said to be a heavyweight object in ADO.NET. This object is based on DataAdapter object and does not have the ability to communicate with data sources. That is, we use the DataAdapter object as a bridge between the DataSet object and the data source. A DataSet contains several datatables, and a DataTableTable contains several datarows.

DataReader: We can use DataReader objects when we only need to read data sequentially and do nothing else. DataReader objects simply read down data from the data source, one ata time. The data is stored in the database server, not loaded into the program’s memory ata time. The data can only be read from the current row (via a cursor), and the data is read-only and not allowed to do anything else. Because the DataReader reads data one ata time and is read-only, it is resource efficient and efficient to use. In addition to being more efficient, using DataReader objects reduces network load because you don’t have to send all the data back.

43. All custom user controls in ASP.NET must inherit from?

The Control class

44. Managed code in.NET always we don’t have to worry about memory leaks because of that?

GC garbage collector.

45. What is the MVC pattern

MVC(Model View Controller) Model-view-controller

Aspx is a View, a View; Model: DataSet, Reader, object; Controller: CS code.

MVC is a typical parallel relationship, it doesn’t say who’s up and who’s down, the model takes care of the business domain, the view takes care of the display, and the controller reads the data and fills the model and gives the model to the view to handle. The validation and all that stuff should be handled in the model. It enforces the separation of input, processing, and output from an application. The biggest benefit of MVC is the separation of logic and page.

46. Requirements for objects to be accessed using foreach

You implement the IEnumerable interface or declare the type of the GetEnumerator method.

47. What is reflection?

An assembly contains modules, and modules include types, and there are members under types. Reflection is an object that manages assemblies, modules, and types. It can dynamically create instances of types, set or get types of existing objects, call methods of types, and access field attributes of types. It creates and consumes type instances at run time.

48. What are the differences between lazy loading and direct loading in ORM?

Lazy Loading reduces unnecessary overhead by Loading data only when it is actually needed.

49. Describe the difference between Func and Action.

Func is a delegate with a return value, and Action is a delegate with no return value.

What are the names of the design modes and how to classify them?

It can be divided into three types: creation type, behavior type and structure type;

The creation pattern includes: 1. singleton pattern 2. factory pattern 3. builder pattern 4. prototype pattern 5. Factory method pattern

Behavioral pattern includes: 1. Strategy pattern 2. Template method pattern 3. Observer pattern 4. Responsibility chain mode 6. Command mode 7. Memo mode 8. Status mode 9. Visitor mode 10. Mediator pattern 11. Interpreter pattern

Structural design patterns include: 1. Adapter pattern 2. Decorator pattern 3. Appearance mode 5. Bridge mode 6. Combination mode 7

More dry goods to follow! Please attention!