. NET pen question set (i)

Source: Internet
Author: User
Tags class definition modifiers reflector server memory

Topics from the wisdom of the podcast and the major Internet, review, re-organized post.

1. Brief description of private, protected, public, internal, protected internal access modifiers and access rights

Private : A privately owned member that can be accessed within a class.

protected: A protected member that can be accessed within the class and in the inheriting class.

Public : Common members, completely public, without access restrictions.

internal: can be accessed in the current assembly.

protected internal: access is limited to the current assembly or to a type derived from the containing class.

Classes without modifiers are the default internal.

2. Brief description of abstract, sealed class modifier

Abstract: A class can be instructed to be used only as a base class for other classes.

Sealed: indicates that a class cannot be inherited.

3. Brief description of C # member modifiers

Abstract: indicates that the method or property is not implemented.

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

Event : declares an event.

extern: indicates that the method is implemented externally.

Override: A new implementation of an inherited member of the radical class.

ReadOnly: indicates that a domain can be assigned only at the time of declaration and within the same class.

static: indicates that a member belongs to the type itself and not to a particular object.

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

4, ADO. Net of five main objects

Connection: The main is to open the connection between the program and the database. It is not possible to get data from the database without using the Connection object to open the database. The difference between close and dispose is that close can be open,dispose later.

command: The main can be used to send some instructions to the database, such as the database can be placed query, add, modify, delete data and other directives, and call the existence of the database stored procedures. This object is schema on the connection object, which is the command: object is connected to the data source by the connection object.

DataAdapter: The main task is to perform data transfer between the source and the dataset, and it can place commands through the command object and put the obtained data into the DataSet object. This object is schema on the command object and provides many features that work with the dataset.

DataSet: This object can be treated as a staging area (Cache), which can keep the data queried from the database, even display the entire database, and the dataset is in memory. The ability of a dataset is not just to store multiple tables, but also to get some data table structures, such as primary keys, through DataAdapter objects, and to record correlations between data tables. The DataSet object can be said to be a heavyweight object in ADO, which is not inherently capable of communicating with the data source on the DataAdapter object, which means we are bridging the DataAdapter object as a DataSet object and transferring data between the data sources. The dataset contains several DataTable, Datatabletable contains several DataRow.

DataReader: You can use the DataReader object when we only need to read the data sequentially and no other action is required. The DataReader object simply reads the data from the data source once in a row, which is present in the database server instead of being loaded into the program's memory at once, and only (through the cursor) reads the current row's data, and the data is read-only and is not allowed to do anything else. Because DataReader restricts reading only one bar at a time while reading the data, it can only be read-only, so it saves resources and is very efficient. The use of DataReader objects in addition to good efficiency, because not all the data back, it can reduce the load of the network.

ADO uses the Connection object to connect to the database, executes the SQL statement using the command or DataAdapter object, and returns the results of the execution to DataReader or DataAdapter. The data results are then manipulated using the obtained DataReader or DataAdapter objects.

5. Enumerate several ways and pros and cons of transferring values between ASP.

1. Using querystring, such as ...? id=1; Response. Redirect (): passed parameters are displayed in the URL, unsafe and cannot be passed the array or object.

2. Use Session variables: simple, but easy to lose action on the user's personal, excessive storage will lead to the depletion of server memory resources.

3. Using Server.Transfer: The process is guided from the current page to another page, the new page uses the previous page's reply stream, the database is stable, secure, but the performance is relatively weak.

4.Cookie Transmit Value: simple, but may not support, may be forged cookie is stored on the client, and the session is stored on the server side. And the use of cookies should be used in conjunction with the ASP.

5.Application Value: The object is scoped to the whole global, which means it is valid for all users. Its usual method is to use lock and unlock

6.PreviosPage: This is generally less used.

Server.Transfer and Response.Redirect differences: Server.Transfer is the server internal transfer, the browser does not know, Response.Redirect is a browser involved, so in the address bar can see the change of address.

6. What is a delegate in C #? Is the event a delegate? Relationship of events and delegates

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

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

Delegates and events are not comparable because the delegate is a type, the event is an object, and the following is the difference between the delegate's object (the event implemented by the delegate) and (the standard event mode implementation) event. The internal of the event is implemented with a delegate. Because for the event, external can only "register themselves + =, write off themselves--", the outside world can not write off other registrants, the outside world can not actively trigger events, so if the delegate can not carry out the above control, so the birth of the event of this grammar. An event is used to castrate a delegate instance, and an analogy is to castrate a list with a custom class. Events can only add, remove themselves, and cannot be assigned a value. Events can only be + =, =, not =. Add-on answer: Inside the event is a private delegate and add, remove two methods.

7. The difference between overriding (override) and overloading (overload)

Override is an override of a function in a base class. Override is an object-oriented concept. The override method provides a new implementation of a member inherited from a base class. Overridden by the Override declaration method is called overriding the base method. The overridden base method must have the same signature as the override method

Overloading is the same as the name of the method. The number of arguments or the type of parameter is different, and multiple overloads are used to accommodate different needs. Overloading (overload) is a process-oriented concept.

8. Can indexers be indexed only by numbers in C #? Do you want to allow multiple indexer parameters?

The number and type of arguments are arbitrary. Using reflector anti-compilation, it can be seen that the internal indexer is essentially a set_item, get_item method.

9. What is the difference between a property and a public field? Call the Set method to set a value for a property, and then the value read out with the Get method must be the value set in?

Attributes can be used to control illegal values for the process of setting a value or value, such as an age-forbidden negative value, and a field that cannot be set. Although the value of a get read is generally the value of a set setting, it is an extreme example that a get read value is not a set value. public Age{get{return 100;} set{}}. Using reflector anti-compilation, we can see that the intrinsic nature of the attribute is set_***, get_*** method.

        Classperson {public int age { get { return 3;}}} static void Main (string[] args) {person P1 = new Person (); P1. Age = p1. age++; Console.Write (P1. Age); // Output 3 console.readkey ();}            

10, three layer architecture

The usual three-tier architecture is to divide the entire business application into the presentation layer (UI), the Business Logic layer (BLL), the data Access Layer (DAL).

The purpose of distinguishing hierarchy is to "high cohesion, low coupling" thought.

presentation Layer (UI): Popular Speaking is the interface that is presented to the user, which is what the user sees when they use a system.

Business Logic Layer (BLL): for the operation of the specific problem, it can also be said that the operation of the data layer, the data business logic processing.

Data Access Layer (DAL): This layer of transactions directly manipulate the database, for the addition of data, delete, modify, update, find and so on each layer is a vertical relationship.

The three-layer structure is a kind of n-layer structure, in general, the hierarchy is down-dependent, the lower layer of code does not determine its interface (contract), the upper code is not developed, the lower layer Code interface (contract) changes will make the upper layer of code changes together.

Advantages: Clear division of labor, clear, easy to debug, but also scalable.

Cons: increased costs.

11. Mvc Mode

MVC (Model View Controller) models-View-Controllers

aspx is view, Model:dataset, Reader, object, Controller:cs code.

MVC is a classic parallel relationship that does not say who is in the next relationship, the model is responsible for the business area of things, the view is responsible for displaying the things that the controller has to read out the data to fill the model and give the model to the view to handle. and a variety of validation should be done in the model. It makes it mandatory to separate the input, processing, and output of the application. The biggest benefit of MVC is separating the logic from the page.

12. What is packing (boxing) and unpacking (unboxing)?

Boxing: converting from a value type to a reference type.

unboxing: converting from a reference type to a value type.

Object obj = null;//reference type

obj = 1;//Boxed, boxing. Wraps a value type as a reference type.

int i1 = (int) obj;//unboxing. Unboxing

13. What is called the application domain (AppDomain)

A boundary that is established by the common language runtime around an object created in the same application scope (that is, from the application entry point, anywhere along the sequence where the object is activated).

Application domains help isolate objects created in one application from objects created in other applications so that run-time behavior can be predicted.

Multiple application domains can exist in a single process. An application domain can be understood as a lightweight process. Play a safe role. Small resource footprint.

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

CTS: Common type System general-purpose systems types. Int32, Int16→int, string→string, Boolean→bool

CLS: Common Language Specification Common Language Specification. different language syntax.

CLR: Common Language Runtime Common Language runtime, that is. NET provides those classes

15. What are the similarities and differences between classes (class) and structure (struct) in dotnet?

Class can be instantiated, is a reference type, and is allocated on the heap of memory. The class is passed by reference.

A struct is a value type that is allocated on the stack of memory. Structs are copied and passed.

16. What is the difference between heap and stack?

Stacks are allocated memory space during compilation, so your code must have a clear definition of the size of the stack, local value type variables, value type parameters, and so on in the stack memory.

A heap is a dynamically allocated memory space during a program's run, and you can determine the size of the heap memory to allocate depending on how the program is running.

17. Requirements for objects that can be accessed with foreach traversal

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

18. What is GC? Why do you have a GC?

GC is a garbage collector. Programmers don't have to worry about memory management because the garbage collector is automatically managed. The GC can only handle the release of managed memory resources, and for unmanaged resources it cannot be recycled using GC, which must be manually recycled by the programmer, an example of which is FileStream or SqlConnection requiring the programmer to call Dispose for resource recycling.

To request garbage collection, you can call the following method: Gc.collection () generally does not require a manual call to Gc.collection ().

19, String s = new string ("XYZ"), and several string Object created?

Two objects, one is "XYZ", and the other is a reference object pointing to "XYZ".

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

1. When you assign a value type variable to another value-type variable, the contained value is copied. The assignment of a reference type variable copies only references to the object, not the object itself.

2. A value type cannot derive a new type: All value types are implicitly derived from System.ValueType. But as with reference types, structs can also implement interfaces.

3. value types may not contain null values: However, the nullable type feature allows NULL to be assigned to a value type.

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

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

Different points:

Interfaces cannot be instantiated directly.

An interface does not contain an implementation of a method.

Interfaces can inherit multiple, and classes can only be single-inherited.

A class definition can be split between different source files.

Same point:

interfaces, classes, and structs can inherit from multiple interfaces.

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

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

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

Same point:

cannot be instantiated directly, it is possible to implement its abstract method through inheritance.

Different points:

Interfaces support multiple inheritance, and abstract classes cannot implement multiple inheritance.

An interface can define behavior only, and an abstract class may define behavior as well as provide implementations.

Interfaces can be used to support callbacks (CallBack), and abstract classes cannot implement callbacks because inheritance is not supported.

The interface contains only methods (method), property, indexer (index), event signature, but cannot define fields and methods that contain implementations;

Abstract classes can define fields, properties, and methods that contain implementations.

Interfaces can be used for value types (structs) and reference types (class), and abstract classes can only be used for reference types. For example, a struct can inherit an interface and not inherit a class.

23. Can I inherit the String class?

The string class is a sealed class and cannot be inherited.

24. There is a return statement in try {}, then the code in the finally {} immediately after this try will not be executed, when is it executed?

Executes before the return.

int Querycount () {  try  { return cmd. ExecuteScalar (); } finally {cmd. Dispose (); }}

If C # is designed to execute CMD first. Dispose () executes return and the return execution fails because CMD is already dispose.

25. New Keyword Usage

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

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

The new constraint is used to constrain the type of a parameter that may be used as a type parameter in a generic declaration.

26, how to copy an array into the ArrayList

Implementation 1 string[] s ={"111", "22222"}; ArrayList list = new ArrayList (); List. AddRange (s);

Implementation 2 string[] s ={"111", "22222"}; ArrayList list = new ArrayList (s);

27. Describe the difference between threads and processes?

1. Threads and processes both define a boundary, but the process defines the boundary between the application and the application, where code and data space cannot be shared between different processes, and threads define the boundaries of the code execution stack and execution context.

2. A process can consist of several threads, while creating multiple threads to accomplish a task, that is, multithreading. and different threads in the same process share code and data space. In a metaphor, if a family represents a process, within the family, each member is a thread, and each member of the family has an obligation to accumulate the wealth of the family, while also having the right to consume the household wealth, and when confronted with a task, the family can also send several members to cooperate to complete, People outside the family have no way of directly consuming property that does not belong to their own family.

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

In C #

int i=3;

I= "a";

No

In JavaScript

var i=3;

I= "a";

OK

A strong type determines the type of data at compile time, the type cannot be changed at execution time, and the weak type determines the type at execution time.

No good, both of them have good, strong type safety, because it has been determined beforehand, and high efficiency. Weaker types are more flexible, but inefficient and have high probability of error

Generally used in compiled programming language, such as c++,java,c#,pascal, weak type compared to unsafe, in the runtime prone to errors, but it is flexible, more for the interpretation of programming languages, such as JAVASCRIPT,VB, etc.

29. What is reflection?

Assemblies contain modules, and modules include types, members under types, reflection is managed assemblies, modules, types of objects, which can dynamically create instances of types, set the type of an existing object, or get the type of an existing object, the method that invokes the type, and the field properties of the access type. It is a type instance that is created and used at run time.

30, int, DateTime, string can be null?

int, DateTime cannot, because it is a struct type, whereas a struct is a value type, a value type cannot be null, and only a reference type can be assigned null. string can be null.

. NET pen question set (i)

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.