C # interview questions (1)

Source: Internet
Author: User
Tags dot net dot net framework

The following questions are my interview questions collected from the internet. I wrote my own answers and asked you to correct any mistakes.

1. What are the differences between property and attribute in C #? What are their respective uses? What are the advantages of this mechanism?
Property usage
Get/set method. It is mainly used for data interaction between classes and external programs. This increases the security and convenience of data access within the class. during compilation, you can perform type check and access permission check.

Attribute usage
[STAThread]
Public void Thrd (){...}
Attribute is a class derived from the System. Attribute base class. Attribute can be enumerated and queried in reflection. (When the compiler sees an attribute attached to a type or member, it searches

System. Attribute derived class with the specified Attribute name. If the compiler does not find a matching class, it adds Attribute after the specified Attribute name and then searches for it. Therefore

It is used to define the Attribute class name as ending with Attribute and ignore this part of the name during use .) You can use Attribute to attach custom information to an object.

Dynamic query. This information can not only be obtained by users as a type of annotation, but can also be recognized by the compiler and used as a subsidiary condition during compilation to compile the program. Example:

[STAThread] and [MTAThread] thread mode attributes can be used to specify whether the thread is in single-thread mode or multi-thread mode. (The thread model only affects applications that use COM interop.

Apply this attribute to programs that do not use COM interop .)
Several common attributes:
AttributeUsage | Class | specify the valid usage of another attribute Class
CLSCompliant | all | indicates whether the program element is compatible with CLS.
Conditional | Method | indicates that if no associated string is defined, the compiler can ignore any calls to this Method.
DllImport | Method | specify the DLL location that contains the implementation of external Methods
STAThread | Method (Main) | specifies that the default thread model of the program is STA.
MTAThread | Method (Main) | specifies that the default program model is multi-thread (MTA)
Obsolete | except Assembly, Module, Parameter, and Return | marks an element as unavailable and notifies users that this element will be used by future products.
ParamArray | Parameter | allows a single Parameter to be implicitly treated as a params (array) Parameter
Serializable | Class, Struct, enum, and delegate | all public and private fields of this type can be serialized.
NonSerialized | Field | it is applied to Fields marked as serializable classes and indicates that these fields cannot be serialized.
StructLayout | Class, struct | specifies the nature of the data layout of a Class or structure, such as Auto, Explicit, or sequential
ThreadStatic | Field (static) | implements local thread storage (TLS ). A given static field cannot be shared across multiple threads. Each thread has a copy of this static field.

2. Let's talk about the web service you understand. In the dot net framework, how can we combine xml well?
I personally understand that web service is a collection of technologies that provide services across networks. It mainly supports a service through various protocols, such as the http (Hypertext Transfer Protocol) Protocol, xml (eXtensible Markup Language), soap (Simple Object Access Protocol) Protocol, WSDL (Web Services Description Language), UDDI (Universal Description, Discovery and Integration ).. . Net framework. This concept mainly describes how to use xml web service as the basic architecture for distributed computing on the Internet. Open Standards and communications, enable collaboration between people and applications, and integrate applications through xml web service to create a platform. Applications are integrated and implemented through xml web Services from different sources. The following is. net's definition of xml web service:
. Xml web service publishes practical functions to web users through a standard protocol. In most cases, this protocol is a SOAP protocol.
. Xml web service describes interfaces in one way. The information must be detailed enough to allow users to implement a customer application based on the information. This Description is usually presented in an xml document (Web Services Description Language.
. Once the xml web service is registered, potential users can easily find these services through the Universal Discovery Description and Integration.

3. What are the characteristics of C #, Java, and c ++? What are the similarities and differences between C # and java?
(1) Similar syntax
(2) Both are object-oriented programming languages. C # and Java are pure object-oriented, while c ++ contains multiple programming modes.
(3) C # and Java all have garbage collection mechanisms, and c ++ memory release requires the control of programmers themselves.
(4) C # and Java are both compiled in an intermediate language mode, and then run in the runtime environment to produce the machine language. C ++ is directly compiled into the machine language.
(5) C #, Java supports single-class inheritance and multi-interface inheritance, while C ++ supports multi-class inheritance.
(6) C # automatically recycles garbage from java, class ticket inheritance and multi-interface inheritance, which facilitates platform transplantation based on a runtime environment,
(7) C #, Java has no pointer, and C ++ has
(8) C # enhances the Java attribute concept and checks the Security type and access control in the compiler. C ++ does not
(9) C #, Java absorbs the idea of C ++ generic programming and the idea of interfaces and makes it a feature of the language.
(10) C # also supports object indexing.
(11) without global variables, they all start from a base class and have their own class architecture. They all use hierarchical namespaces to control the system without header file concepts.

4. C # Can I perform direct operations on the memory?
You can perform this operation directly, but you only need system APIs, such as OpenMapingFile. Since we cannot use pointers in managed code, we need to use the unsafe flag to declare and use pointers to operate on memory. I will discuss the issue of c # Memory Allocation in another article.

5. How to combine the unmanaged code written in Visual C ++ 6.0 with other dot net component in CLR?
Compile the unmanaged code into a dll, and then import the published method to the framework using the DllImport attribute.

6. What is the delegate in C? Is an event a delegate?
The delegate can be viewed as a managed pointer encapsulated by. net. To use the delegate, you must first define the delegate and then declare the delegate variable. An event is a delegate.

7. To describe the implementation process of the indexer in C #, can I index data only by numbers?
The indexer in C # is implemented by a special attribute "this []". It can also be indexed by other types, such as strings.

8. How does one implement a class that supports FOREACH traversal in C?
Class to implement the IEnumerable interface, and return an IEnumerator object through the GetEnumerator () of the IEnumerable interface.

Class CountryList: IEnumerable {
Private ArrayList m_list;

Public CountryList (){
M_list = new ArrayList ();
M_list.Add ("China ");
M_list.Add ("America ");
M_list.Add ("England ");
}

Public IEnumerator GetEnumerator (){
Return m_list.GetEnumerator ();
}
}

9. Do you know about XMLHTTP and WEBSERVICE? Briefly describe its features and functions?

XMLHTTPIt is a set of API functions that can be called by JavaScript, JScript, VBScript, and other embedded scripting languages in web browsers. XML or other data can be sent and received between browsers and web servers through HTTP. The biggest benefit of XMLHTTP is its ability to dynamically update webpages without re-reading the entire webpage from the server or installing additional plug-ins. This technology is used by many websites to achieve fast response to dynamic web applications. For example, Google's Gmail service, Google Suggest dynamic search interface, and Google Map's geographic information service.

XMLHTTP isAJAXAn important part of web development technology.

In addition to XML, XMLHTTP can also be used to obtain data in other formats, such as JSON or even plain text.

WebService is defined by W3C organizations as "a software system is designed to support cross-network operations from machines to machines ". WebService often uses Web APIs to access and execute services on the remote system across networks.

10. What is the difference between interfaces and abstract classes? What is the basis for using interfaces and abstract classes?
An interface is a class that is more restrictive than an abstract class. An interface cannot own entities, but an abstract class can have entities. When defining a specification, an interface is used, and an abstract class is used in the design class system.

11. What is the error handling mechanism of. net?
Exception Handling: throws an exception and uses the try... catch... finally keyword in the code block to capture and process the exception .. . Net all Exception classes are inherited from the System. Exception class.

12. Do you know the design mode? List the names of the design patterns you know.
A better solution to the problem in a specific environment.
Single-piece mode, bridging mode, factory mode, abstract factory mode, builder mode, adapter mode, observer mode, and combination mode.

13. What is Application Pool?
An application pool is a configuration that links one or more applications to one or more worker processes. Applications in the application pool are separated from other applications by working process boundaries. Therefore, applications in an application pool are not affected by problems caused by applications in other application pools.

14. How can Remoting be implemented on the client server?
15. What is an application domain? What is regulated code? What is a strong system? What is packing and unpacking? What is overload? What are the explanations of CTS, CLS, and CLR?
The application domain is an environment provided by. net framework for executing hosted code. This environment provides an isolated and undetachable security boundary. You can load accessories or executable programs in an application domain. In addition, if an error occurs in an application domain, you can detach it without worrying about affecting the work of other application domains.

Managed code is the code written for services of the Public Language Runtime Library.

A strongly typed system has strict requirements and restrictions on data types. Each variable and expression has a type. The system checks the type before using a variable.

Simply put, packing is to convert the value type to the reference type, while unpacking is the opposite process.

Overload is to assign different parameter lists to functions with the same name to meet the same access requirements: for example:
Void Output (string name ){}
Void Output (string name, int start ){}

CTS: common type system, mainly for standardization between languages.
CLS: The minimum standard group that ensures code access in any language
CLR: when running in a common language, it mainly manages code, processes, loads code, and Code of all services.

 

Related Article

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.