. Net question set (1)

Source: Internet
Author: User

The questions come from the Chuanzhi podcast and the Internet. They are reviewed and re-posted.

1. Brief Introduction to private, protected, public, internal, and protected internalAccessModifier and access permission

PRIVATE:Private Members can be accessed within the class.

Protected:Protects members, which can be accessed inside the class and in the inherited class.

Public:Public members are completely public, with no access restrictions.

Internal:CurrentProgramSet.

Protected internal:Access is limited to the current Assembly or a type derived from the include class.

Classes without modifiers are default internal.

 

2. Brief description of abstract and sealed class Modifiers

Abstract:It can be indicated that a class can only be used as the base class of other classes.

Sealed:Indicates that a class cannot be inherited.

 

3. C # member Modifier

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

Const:The value of the specified domain or local variable cannot be changed.

Event:Declare an event.

Extern:The indication method is implemented externally.

Override:The new implementation of the inherited members of the base class.

Readonly:Indicates that a domain can only be assigned a value when declared and inside the same class.

Static:Indicates that a member belongs to the type rather than a specific object.

Virtual:Indicates that the implementation of a method or accessor can be overwritten in the inheritance class.

 

4. Five main objects in ADO. net

Connection:It is mainly used to enable the connection between the program and the database. Data cannot be obtained from the database because the database is not opened using the connection object. The difference between close and dispose is that you can open it after close, and you cannot use it after dispose.

Command:It can be used to send commands to a database, such as sending query, addition, modification, and deletion commands to a database, and calling stored procedures in a database. This object is structured on the connection object, that is, command: the object is connected to the data source through the connection object.

Dataadapter:Data transmission is performed between data sources and Dataset. After commands are issued through the command object, the obtained data can be placed into the DataSet object. This object is structured on the command object and provides many functions used with dataset.

Dataset:This object can be regarded as a cache. It can retain the data queried from the database, and even display the entire database. dataset is stored in the memory. Dataset can not only store multiple tables, but also obtain data table structures such as primary keys through the dataadapter object and record the association between data tables. The DataSet object can be called ADO. net heavyweight object, which is structured on the dataadapter object and does not have the ability to communicate with the data source. That is to say, we use the dataadapter object as the DataSet object and a bridge between data sources for data transmission. Dataset contains several datatables and ableabletable contains several datarow.

Datareader:You can use the datareader object to read data in sequence instead of other operations. The datareader object only reads data from the data source in a descending order at a time. The data is stored in the database server, instead of being loaded to the memory of the program at a time. Only the data can be read through the cursor) read the data of the current row, and the data is read-only. Other operations are not allowed. Because datareader restricts reading only one data entry at a time and can only be read-only, it not only saves resources but also improves efficiency. In addition to high efficiency, datareader can reduce network load because it does not need to transmit all data.

ADO. net uses the connection object to connect to the database, uses the command or dataadapter object to execute the SQL statement, and returns the execution result to datareader or dataadapter, then use the obtained datareader or dataadapter object to operate the data results.

 

5. list several methods and advantages and disadvantages of passing values between ASP. NET pages

1. Use querystring, such ....? Id = 1; response. Redirect ():The passed parameters are displayed in the URL, Which is insecure and cannot pass arrays or objects.

2. Use session variables:It is simple, but it is easy to lose and act on individual users. Excessive storage will result in the depletion of server memory resources.

3. Use server. Transfer:The process is directed from the current page to another page. The new page uses the response stream of the previous page. The database is stable and secure, but the performance is relatively weak.

4. Cookie values:It is simple, but may not be supported. The cookie may be forged and stored on the client, while the session is stored on the server. In addition, cookies must be used in combination with ASP. NET built-in object requests.

5. Application Value:The scope of the object is global, that is, it is valid for all users. Its common methods are lock and unlock.

6. previspage:This is generally less useful.

Server. transfer and response. redirect: Server. transfer is the internal transfer of the server, the browser does not know; response. redirect involves browsers, so you can see the address changes in the address bar.

 

6. What is the delegate in C? Is an event a delegate? Relationship between events and Delegation

A delegate can substitute a method as a parameter into another method.

The delegate can be understood as a pointer to a function.

The delegate and event are not comparable, because the delegate is a type, and the event is an object. The following describes the delegate objects (events implemented using the delegate method) and (implemented using the standard event method) event differences. Internal events are implemented by delegation. For an event, you can only register yourself + = or deregister yourself-=. other registrants cannot be deregistered, or the event cannot be triggered, therefore, if delegate is used, the above control cannot be implemented, so the event syntax is born. The event is used to caster the delegated instance, similar to a custom class castrated list. Events can only be added or removed, but cannot be assigned values. The event can only be + =,-=, and cannot be =. In addition, the event is a private delegate, add, and remove methods.

 

7. Differences between override and overload

Override is used to override functions in the base class. Override is an object-oriented concept. The override method provides a new implementation of Members inherited from the base class. The method declared by override is called the override base method. The overwritten base method must have the same signature as the override method.

Overload means that the method name is the same. If the number or type of parameters are different, perform multiple reloads to meet different requirements. Overload is a process-oriented concept.

 

8. Can I index the index in C # Only by numbers? Are multiple indexer parameters allowed?

The number and type of parameters are arbitrary. Reflector decompilation shows that the internal indexer is essentially the set_item and get_item methods.

 

9. What is the difference between attributes and public fields? Call the set method to set a value for an attribute, and then use the get method to read the value must be set in the value?

Attribute can be used to control the process of setting values or values. For example, you cannot set a negative value for an age, but cannot set a field. Although the value read by get is set, the value read by get is not set. An extreme example is given. Public age {get {return 100;} set {}}. Reflector decompilation shows that the SET _ *** and get _ *** methods are essentially internal attributes.

         Class  Person {  Public   Int  Age { Get  {  Return   3  ;}}}  Static   Void Main ( String  [] ARGs) {person p1 = New  Person (); p1.age = 30  ; P1.age ++; Console. Write (p1.age );  //  Output 3
Console. readkey (); }

 

10. Three-tier architecture

Generally, the three-tier architecture divides the entire business application into: presentation layer (UI), business logic layer (BLL), and data access layer (DAL ).

The purpose of hierarchy differentiation is the idea of "high cohesion and low coupling.

Presentation layer (UI ):In general, it is the interface displayed to the user, that is, what the user sees when using a system.

Business logic layer (BLL ):Operations for specific problems can also be called operations on the data layer and data business logic.

Data access layer (DAL ):Transactions made at this layer directly operate on the database, and there is a vertical relationship between each layer, such as adding, deleting, modifying, updating, and searching data.

A layer-3 structure is a type of N-layer structure. Generally, layers depend downward, while LayersCodeBefore determining its interface (contract), the upper-Layer Code cannot be developed, and the changes to the lower-Layer Code interface (contract) will change the upper-Layer Code together.

Advantages:The division of labor is clear, clear, easy to debug, and scalable.

Disadvantages:Increase costs.

 

11. MVC Mode

Model View Controller (MVC) Model-View-Controller

Aspx is the view, view; model: dataset, reader, object; Controller: CS code.

MVC is a typical parallel relationship. It doesn't mean who is in the relationship, the model is in charge of the business field, and the view is in charge of the display, the Controller reads the data and fills the model. Then, the model is handed over to the view for processing. Various verifications should be handled in the model. It forcibly separates application input, processing, and output. The biggest benefit of MVC is the separation of logic and page.

 

12. What is boxing and unboxing )?

Packing:Converts a value type to a reference type.

Unpack:Converts a reference type to a value type.

Object OBJ = NULL; // reference type

OBJ = 1; // boxed, boxing. Wrap the value type as the reference type.

Int I1 = (INT) OBJ; // unpack. Unboxing

 

13. What is an application domain)

A boundary that is built by the Common Language Runtime Library around the objects created within the same application range (that is, any location in the sequence of object activation starting from the application entry point ).

The application domain helps isolate the objects created in one application from those created in other applications for predictable runtime behavior.

Multiple application domains can exist in a single process. The application domain can be understood as a lightweight process. Security. Small resource occupation.

 

14. What are the explanations of CTS, CLS, and CLR?

CTS:Common Type System common system type. Int32, int16 → int, string → string, Boolean → bool

CLS:Common Language Specification. Different Languages have different syntaxes.

CLR:Common Language Runtime is the class provided by. net.

 

15. What are the similarities and differences between classes and struct in DOTNET?

Class can be instantiated, which belongs to the reference type and is allocated to the memory stack. Class is passed by reference.

Struct is a value type and is allocated to the memory stack. The struct is copied and transmitted.

 

16. What is the difference between stack and stack?

Stack is the memory space allocated during compilation. Therefore, the size of the stack must be clearly defined in your code. Local value type variables and value type parameters are all in the stack memory.

Heap is the memory space dynamically allocated during the program running. You can determine the size of heap memory to be allocated based on the program running status.

 

17. Requirements on objects accessed with foreach Traversal

You need to implement the ienumerable interface or declare the type of the getenumerator method.

 

18. What is GC? Why does GC exist?

GC is the garbage collector. Programmers do not have to worry about memory management, because the Garbage Collector will automatically manage. GC can only process the release of managed memory resources. For unmanaged resources, GC cannot be used for recovery and must be manually recycled by programmers, one example is that filestream or sqlconnection requires the programmer to call dispose to recycle resources.

To request garbage collection, you can call the following method: GC. Collection () generally does not need to manually call GC. Collection ().

 

19. String S = new string ("XYZ"); how many string objects are created?

Two objects, one being "XYZ" and the other being referenced objects pointing to "XYZ.

 

20. What is the difference between the value type and the reference type?

1.When a value type variable is assigned to another value type variable, the included values are copied. The value assignment of the reference type variable only copies the reference to the object, instead of copying the object itself.

2.The value type cannot be derived from a new type: All value types are implicitly derived from system. valuetype. But what is the same as the reference type is that the structure can also implement interfaces.

3.The value type cannot contain null values: However, the null type function allows null to be assigned to the value type.

4.Each value type has an implicit default constructor to initialize the default value of this type.

 

21. What are the similarities and differences between interfaces and classes in C.

Differences:

The interface cannot be instantiated directly.

The interface does not contain the implementation of methods.

The interface can be inherited multiple times, and the class can only be inherited individually.

Class definition can be split between different source files.

Similarities:

Interfaces, classes, and structures can all be inherited from multiple interfaces.

An interface is similar to an abstract base class: any non-Abstract type that inherits an interface must implement all the members of the interface.

Both interfaces and classes can contain events, indexers, methods, and attributes.

 

22. What is the difference between abstract class and interface?

Similarities:

They cannot be directly instantiated. They can all be inherited to implement their abstract methods.

Differences:

Interfaces support multi-inheritance; abstract classes cannot implement multi-inheritance.

An interface can only define behaviors. An abstract class can either define behaviors or provide implementations.

Interfaces can be used to support callback. abstract classes cannot implement callback because inheritance is not supported.

The interface only contains the signatures of methods, properties, indexes, and events. However, fields and methods that contain implementations cannot be defined;

Abstract classes can define fields, attributes, and include implementation methods.

The interface can act on the Value Type (struct) and reference type (class); the abstract class can only act on the reference type. For example, struct can inherit interfaces rather than classes.

 

23. Can I inherit the string class?

Because the string class is a sealed class, it cannot be inherited.

 

24. If there is a return statement in try {}, will the code in finally {} following the try be executed? When will the code be executed?

Will be executed, before return.

Public IntQuerycount (){Try{ReturnCmd. executescalar ();}Finally{Cmd. Dispose ();}}

If C # is designed to execute cmd. Dispose () and then execute return, the return execution fails because cmd has already dispose.

 

25. New Keyword usage

The new operator is used to create objects and call constructors.

The new modifier is used to hide an inherited member from a base class member.

The new constraint is used to restrict the types of parameters that may be used as type parameters in a generic declaration.

 

26. How to copy an array to arraylist

Implement 1 string [] S = {"111", "22222"}; arraylist list = new arraylist (); list. addrange (s );

Implement 2 string [] S = {"111", "22222"}; arraylist list = new arraylist (s );

 

27. What is the difference between a thread and a process?

1. both threads and processes define some boundary. The difference is that processes define the boundary between applications, different processes cannot share code and data space, while threads define the boundary of code execution stack and execution context.

2. A process can contain several threads and create multiple threads to complete a task at the same time, that is, multithreading. Different threads in the same process share code and data space. In a metaphor, if a family represents a process, each member in the family is a thread, and every member in the family is obligated to accumulate wealth in the family, at the same time, the family has the right to consume family wealth. when facing a task, the family can also send several members to complete the work together, people outside the family cannot directly consume the property of their own families.

 

28. What is strong type and weak type? Which one is better? Why?

C # Medium

Int I = 3;

I = "";

No

In Javascript

VaR I = 3;

I = "";

Yes

A strong type determines the type of data during compilation. The type cannot be changed during execution, but the weak type determines the type during execution.

No, either of them has its own advantages. Strong type security, because it has been determined in advance, and the efficiency is high. The weak type is more flexible, but the efficiency is low, and the error probability is high.

It is generally used for compilationProgramming LanguageSuch as C ++, Java, C #, Pascal, etc. The weak type is not safe in comparison and may cause errors during running. However, it is flexible and mostly used in interpreted programming languages, such as JavaScript and VB

 

29. What is reflection?

An Assembly contains a module, and a module includes a type. There are members under the type. Reflection is the management assembly, module, and type object. It can dynamically create instances of the type, set the existing object type or obtain the existing object type. You can call the method of the type and the field attribute of the access type. It is created and used at runtime.

 

30. Can int, datetime, and string be null?

INT and datetime cannot be used because they are of the struct type, while the structure belongs to the value type. The value type cannot be null. Only the reference type can be assigned null. String can be null.

 

Author: forevernome
Source: http://www.cnblogs.com/ForEvErNoME/
You are welcome to repost or share it, but be sure to declare it Article Source. If the article is helpful to you, I hope you can Recommendation Or Follow

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.