Classic C # Programming comprehension, overview, Classic

Source: Internet
Author: User
Tags xpath

A. NET Framework

Ado. NET Microsoft provides a set of class libraries that can help programmers interact with databases.

CLS (Common Language Specification) CTS (Common language type)

Class Library:

Can be seen as a container that hosts n classes.

Class libraries and namespaces:

A class library corresponds to a namespace, or multiple.

Two. Automatic attributes

public string Name{set;get;}

Application Scenarios:

When you don't have to make a logical decision, you can use automatic attributes.

Three. Encapsulation

Information hiding, which combines abstract data and operations to encapsulate private fields as public properties.

1. Ensure the security of your data.

2. Provide a clear external interface.

3. The internal implementation of the class can be arbitrarily modified without affecting other classes.

OOP object-oriented programming.

AOP-oriented tangent programming

Ood Object-oriented design

OOA Object-Oriented analysis

DBA Database administrator

CLS (Common Language Specification)

CLR (Common language Runtime) CTS (same type)

. NET Framework primary key

FCL in-Frame library

Chapter II:

Definition of structure:

1. The struct keyword is a struct.

2. You can assign a value to a property without new.

3. When a struct is not new, name cannot be an automatic attribute.

4. A struct is a value type, and class is a reference type.

5. You cannot assign an initial value to a field in a struct, in a class.

6. Structs cannot generate constructs, and classes are automatically formed in the background.

public struct student{public int id;public int age;public void Show () {Console. WriteLine ("Age:" Id,age);}} stattic void Main (String[]args) {student Stu; Create student structure stu.id=1001; stu.age=20;stu.show ();}

Value passing, reference type

The pass-through value type is not persisted and the pass-through reference type is persisted.

1. If a parameter is pre-specified, ref will be retained.

2. If there is no ref before the parameter, you want to keep the reference type itself.

3 value types are not nullable and reference types can be null.

4. The value type is assigned to the stack, and the reference type is saved on the heap.

Three sets:

Collection: Put a bunch of data together.

ArrayList list=new ArrayList ();

foreach (object item in list)

{

Console. WriteLine (item);

}

List. RemoveAt (1); Delete the data labeled 1

1. Introducing namespaces using ArrayList

2. Set expansion principle: the number of elements in the set is 0, there is no space to open up.

3. The first element appears in the default collection, then the collection size is 4, and if you put the fifth element, then the expansion is 8.

Hashtable table=new Hashtable ();

foreach (string key in Table.keys)

{

Console.wirteline (Key,table[key]);

}

The Hashtable type can only be traversed with a Foreach loop in the collection because there is no index.

He is disorderly, the key value can not be repeated, can not be used RemoveAt (1);

List<> list=new list<>

He is similar to ArrayList,list<> does not require type conversion when accessing data.

Dictionary<k,y> diy=new dictionary<k,y>

A generic collection can be used as a property of a class, and a generic collection must be instantiated.

Four. Methods of the class

constructor function

No reference

Public SE ()

{

This.id= "00";

This.name= "Xiao Wen";

}

Main Method ()

Se en=new se ();

Console.WriteLine (en.se);

With reference

Public SE (String name,int age)

{

This.name=name;

This.age=age;

}

Method overloading

If the method name is the same, the parameter list (number, order, type) is different, regardless of the method return value.

The constructor is identical to the class name, and the constructor does not declare the return value, using the public type.

Five. Inheritance polymorphism

Inheritance Benefits:

Reduce code redundancy and implement code reuse.

If a class is followed by a colon and followed by another class, the class preceding the colon is a subclass, and the class after the colon is the parent class, which is the inheritance relationship.

Subclasses cannot inherit constructs

Sub-class: derived class;

Parent class: base class

Two major features of inheritance

Uniqueness, a class can have only one direct parent class.

Base keyword and protected modifier

The base call construct (parameter list) is the same as the parameters of the parent class parameter construction.

public string Sayhi ()

{

String message=string. Format ("Good everyone {0}, this year {1} years old", Base.name,base. Age);

}

Polymorphic

Different objects are different for the same operation and are intended for uniform invocation.

Public virtual string Sayhi ()

{

}

Public Overrde string Sayhi ()

{

}

Implementing polymorphic

1. Define the Sayhi () method in the parent class and define the virtual method with the virtual keyword.

2. In subclasses, the subclass's own Sayhi () method, with the override keyword modifier, implements the override of the parent class method.

Six. In-depth polymorphism

1. A class is decorated with an abstract, which is an abstraction class

2. Abstract classes cannot be instantiated

3. Abstract methods cannot have method bodies

4. Abstract methods must be in an abstract class

5. Abstract methods exist in order to constrain subclasses, the Chinese side sends.

6. Abstract classes cannot be static or sealed (staled)

7. All abstract methods in an abstract class must be overridden by subclasses, unless the subclass itself is an abstract class.

Public abstract class Job

{

Public Jop () {}

public abstract void Execute ();

}

public override void Execute ()

{

}

Richter substitution principle: Subclass objects can replace parent class objects.

Three main features of object-oriented

Encapsulation: Ensuring the integrity and security of the object's own data

Inheritance: Establish a relationship between classes and implement code reuse.

Polymorphic: The same method invocation can implement different implementations.

Seven. XML

Parsing xml

private void Button1_Click (object sender, EventArgs e) 2         {3              XmlDocument doc = new XmlDocument ();4              Doc. Load (@ ": \.. \cd.xml "); 5 6             XmlElement root = null;7              root = Doc. Documentelement;8 9             XmlNodeList ListNodes = null;10             ListNodes = root. SelectNodes ("/bookstore/book/price");11              foreach (XmlNode node in listnodes) 12              {13&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&Nbsp;      richTextBox1.Text + = node. InnerText + "\ n";14            }15         }

Encoding
Type: System.String

The value of the encoding method property. This is the encoding used when XmlDocument is saved to a file or stream, so it must be set to a string supported by the Encoding class, otherwise save fails. If this is a nullnothingnullptrnull reference (nothing in Visual Basic) or String.Empty, the Save method does not write out the encoding property on the XML declaration, so the default encoding UTF-8 is used.

Note: If you save XmlDocument to TextWriter or XmlTextWriter, the encoded value is discarded. Instead, use the TextWriter or XmlTextWriter encoding method. This ensures that the XML written out can be read back using the correct encoding.

2. Methods of the XmlDocument class

The methods and descriptions of the XmlDocument class are shown in the following table.

Method

Description

AppendChild

Adds the specified node to the end of the list of child nodes of the node

CreateAttribute

Creates a XmlAttribute with the specified name

Createcdatasection

Creates a xmlcdatasection that contains the specified data

Createcomment

Creates a xmlcomment that contains the specified data

Createdocumentfragment

Create XmlDocumentFragment

CreateDocumentType

Returns the new XmlDocumentType object

CreateElement

Create XmlElement

Createentityreference

Creates a xmlentityreference with the specified name

CreateNavigator

Create a new XPathNavigator object to navigate this document

CreateNode

Create XmlNode

Createprocessinginstruction

Creates a xmlprocessinginstruction with the specified name and data

Createsignificantwhitespace

Create a XmlSignificantWhitespace node

createTextNode

Creates a XmlText with the specified text

Createwhitespace

Create a XmlWhitespace node

Createxmldeclaration

Creates a XmlDeclaration node with the specified value

getElementById

Gets the XmlElement with the specified ID

getElementsByTagName

Returns a XmlNodeList that contains a list of all elements that match the specified name

Getnamespaceofprefix

Finds the closest xmlns declaration within the current node range from the given prefix and returns the namespace URI in the declaration

Getprefixofnamespace

Finds the closest xmlns declaration in scope of the current node to the given namespace URI and returns the prefix defined in the Declaration

GetType

Gets the Type of the current instance

ImportNode

Import a node from another document into the current document

InsertAfter

Inserts the specified node immediately after the specified reference node

InsertBefore

Inserts the specified node immediately before the specified reference node

Load

Loads the specified XML data

LoadXml

Loads an XML document from the specified string

Normalize

Convert xmltext nodes to "normal" form

PrependChild

Adds the specified node to the beginning of the list of child nodes of the node

ReadNode

Creates a XmlNode object based on the information in XmlReader. The reader must be positioned on a node or attribute

RemoveAll

Remove all child nodes and/or attributes from the current node

RemoveChild

Removes the specified child node

ReplaceChild

Replace old node with new node

Save

Save the XML document to the specified location

SelectNodes

Select a node list that matches an XPath expression

selectSingleNode

Select the first XmlNode that matches the XPath expression

Supports

Test whether the DOM implementation implements specific functionality

Validate

Verify that XmlDocument is not the XML schema definition language (XSD) schema that is contained in the Schemas property.

WriteContentTo

Saves all the children of the XmlDocument node to the specified XmlWriter

WriteTo

Saves the XmlDocument node to the specified XmlWriter

Eight.

File operations

Append

If there is a file, open the file and find the end of the file, or create a new file. This requires Fileiopermissionaccess.append permissions. Filemode.append can only be used with FileAccess.Write. An IOException exception is thrown when an attempt is made to find a position before the end of the file, and any attempt to read will fail with an NotSupportedException exception thrown.

Create

Specifies that the operating system should create a new file. if the file already exists, it will be overwritten. This requires Fileiopermissionaccess.write permissions. FileMode.Create is equivalent to a request that uses CreateNew if the file does not exist, or Truncate. if the file already exists but is a hidden file, a UnauthorizedAccessException exception is thrown.

CreateNew

Specifies that the operating system should create a new file. This requires Fileiopermissionaccess.write permissions. if the file already exists, a IOException exception is thrown.

Open

Specifies that the operating system should open an existing file. the ability to open a file depends on the value specified by the FileAccess enumeration. throws a System.IO.FileNotFoundException exception if the file does not exist.

OpenOrCreate

Specifies that the operating system should open the file (if the file exists), otherwise a new file should be created. If you open the file with FileAccess.Read, you need FileIOPermissionAccess.Read permissions. If file access is FileAccess.Write, fileiopermissionaccess.write permissions are required. If you open the file with FileAccess.ReadWrite, you also need to

Truncate

Specifies that the operating system should open an existing file. when the file is opened, it is truncated to a size of 0 bytes. This requires Fileiopermissionaccess.write permissions. attempting to read from a file opened with filemode.truncate will result in an ArgumentException exception.

Classic C # Programming comprehension, overview, Classic

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.