. NET-related knowledge points

Source: Internet
Author: User
Tags prototype definition

1. The differences between C # abstract classes and interfaces

Abstract class

(1) Abstract methods are declared only, not implementations, and can be seen as virtual methods without implementing the body.
(2) Abstract classes cannot be instantiated
(3) Abstract classes can, but do not have to have abstract attributes and abstract methods, but once you have an abstract method, you must declare this class as an abstract class
(4) The specific derived class must override the abstract method of the base class
(5) An abstract derived class can override an abstract method of a base class, or it can be overridden. If not overridden, their specific derived classes must overwrite them

Interface

(1) interface cannot be instantiated
(2) The interface can only contain method declarations
(3) The members of an interface include methods, properties, indexers, events
(4) The interface cannot contain constants, fields (domains), constructors, destructors, static members

Same point:
(1) Can be inherited
(2) can not be instantiated
(3) can contain method declarations
(4) A derived class must implement a method that is not implemented
Difference
(1) Abstract base classes can define fields, properties, method implementations. An interface can only define properties, indexers, events, and method declarations, and cannot contain fields.
(2) An abstract class is an incomplete class that needs further refinement, while an interface is a code of conduct. Microsoft's custom interface is always behind the able field, proving that it is stating a class of "I can do ... ”
(3) Interfaces can be multiple implementations, abstract classes can only be inherited by a single
(4) The abstract class is more defined in a series of closely related classes, and the interface is mostly loose but all of the classes that implement a function
(5) Abstract class is the concept of abstraction from a series of related objects, so it reflects the internal commonality of things; an interface is a functional contract defined to satisfy an external invocation, so it reflects the external nature of the thing.
(6) The interface basically does not have any specific characteristics of inheritance, it only promises to be able to invoke the method
(7) interfaces can be used to support callbacks, and inheritance does not have this feature
(8) The concrete method of the abstract class implementation is virtual by default, but the interface method in the class that implements the interface defaults to non-virtual, and of course you can declare it as virtual.
(9) If an abstract class implements an interface, it is possible to map a method in an interface to an abstract class as an abstract method without having to implement a method in the subclass of an abstract class to implement an interface


2. The five main objects of ADO

1, Connection: Establish a connection with the data source.
2. Command: Executes the SQL command against the data source and returns the result.
3. DataReader: Reading data from a data source, only allows the data source to be viewed in a read-only, forward-looking way to view the data stored in it. It is often used to retrieve large amounts of data, and the DataReader object is also a very resource-efficient data object.
4. DataAdapter: Perform an operation on the data source and return the result, establish communication between the dataset and the data source, write data from the data source to the dataset, or bind the data source based on the data in the dataset.
5, DataSet: In-memory database, is a collection of data tables, it can contain any number of data tables.

using (SqlConnection connection = new SqlConnection (connectionString)) {SqlCommand  Command = new SqlCommand (); Command.  Connection = Connection;  Command.commandtext = "SalesByCategory"; When the CommandType property is set to StoredProcedure, the CommandText property should be set to the name of the stored procedure command.commandtype = CommandType.StoredProcedure;  Set execution type to stored procedure SqlParameter parameter = new SqlParameter (); Parameter. ParameterName = "@CategoryName";//Specifies the parameter parameter in the stored procedure. SqlDbType = sqldbtype.nvarchar;//Specifies the data type parameter. Direction = parameterdirection.input;//Specifies that the parameter is an input parameter.  Value = CategoryName; Command.  Parameters.Add (parameter); Connection.  Open (); SqlDataReader reader = command.  ExecuteReader (); if (reader. HasRows)//Determine if there is a data row {while (reader).  Read ()) {Console.WriteLine ("{0}: {1:c}", Reader[0], reader[1]);  }} else {Console.WriteLine ("No rows found."); } reader.  Close ();//Remember to turn off Console.ReadLine (); } 
public static DataSet ExecuteQuery (String sql) {DataSet ds = new DataSet (); SqlDataAdapter da = new SqlDataAdapter (SQL,CONNSTR);d A. Fill (DS); return DS;}

3. Delegates and Events

(1) The definition of a delegate: a delegate is a type of reference method. Once a delegate has been assigned a method, the delegate will have the same behavior as the method. A delegate method can have parameters and return values, just like any other method. A delegate can be thought of as an abstraction of a function (method), a "class" of a function, an instance of a delegate representing one (or more) specific functions, which can be multicast.
(2) Event: The event is based on a delegate and provides a publish/subscribe mechanism for the delegate. Use "+ =" in the subscription of the event, and the cancellation of the event with "-=".

(delegates can be called directly, and events require certain actions to be triggered)


4. Code specification for the. Net Framework
The name of the delegate type should end with EventHandler.
Prototype definition of a delegate: there is a void return value and accepts two input parameters: an object type, a EventArgs type (or inherited from EventArgs).
The name of the event is the remainder of the delegate after the EventHandler is removed.
Types that inherit from EventArgs should end with EventArgs.





. NET-related knowledge points

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.