Introduction: Learning C # Programming should be a few months, as a rookie, not qualified to comment on what. Only a summary of what you have learned, there may be not rigorous place, million hope understanding.
One • In-depth. NET Framework
. NET Framework (. NET frameworks), which he is developing. NET application is the core Foundation.
. NET Framework Architecture
Support the development of C #, VB,. NET, C + +, and other languages, which is what we call cross-language development.
. The NET Framework has two main components: the CLR and the FCL. (The CLR is common Language runtime, which is the common language; FCL is the Framework class library
. NET Framework Core class library and its functions
Classes and objects
class defines a set of conceptual models, and objects are real entities.
The set accessor is write-only, and the get accessor is read-only.
In VS Automatic properties prop+ Double-click the TAB key
Packaging
1. Ensure the security of your data.
2. Provide a clear external interface
3. Classes can be arbitrarily modified inside, without affecting other classes.
Class diagram
Two. Drill down into C # data types
Value type Application type
Value types include basic data types, enumeration types, struct bodies, and so on.
Reference types include string arrays, classes, and interfaces.
Structure:
There can be fields that can have methods.
The field cannot be assigned an initial value when defined.
No new. You must assign an initial value to a struct member after declaring the struct object.
Unpacking and boxing
Example:
int a=1;
Object o=i;//Boxing
int j= (int) o;//unpacking
Value passing and reference passing
When a reference type is used as a parameter:
1. When modifying the variable itself, the result is similar to a value pass, that is, the value of the variable before the pass is not changed
2. When modifying a variable's property or field, it is the reference pass that affects the value of the variable before it is passed
3, the parameter uses ref, is the true reference pass, regardless of the variable itself or modify the variable's property or field, will affect the value of the variable before passing
Value passing: A copy of the value of the object is passed. (that is, a parameter object inside a function is a copy of an object in the stack of objects passed at the time of invocation.) )
Reference passing: The address of the object in the stack is passed. (That is, the object passed from the parameter object in the function to the call is exactly the same stack.) )
Three. Organize related data using collections
The System.Collections namespace contains interfaces and classes that define a collection of various objects such as lists, queues, bit arrays, hash tables, and dictionaries.
The System.Collections.Generic namespace contains interfaces and classes that define generic collections, which allow users to create strongly typed collections that provide better type security and performance than non-generic strongly typed collections.
The System.Collections.Specialized namespace contains a dedicated and strongly typed collection, such as a linked list dictionary, a bit vector, and a collection that contains only strings.
using system;using system.collections.generic;using System.Text;using System.collections;namespace consoleapplication1{class Program {static void Main (string[] args) { ArrayList list = new ArrayList (); Console.WriteLine ("Traversal Method One:"); foreach (int item in list)//Do not cast {Console.WriteLine (item);//Traversal method one} Con Sole. WriteLine ("Traversal Method II:"); for (int i = 0; i < list. Count; i++)//array is length {int number = (int) list[i];//Be sure to cast Console.WriteLine (number); /Traversal Method Two}}}}
1. Hash table (Hashtable) Summary
In the. NET framework, Hashtable is a container provided by the System.Collections namespace that handles and behaves like Key/value key-value pairs, where key is typically used for quick lookups, while key is case-sensitive ; value is used to store the value corresponding to key. Key/value Key-value pairs in Hashtable are all object types, so hashtable can support any type of Key/value key-value pair.
2. Simple operation of hash table
Add a Key/value key value pair to the hash table: Hashtableobject.add (Key,value);
Remove a Key/value key value pair in the hash table: Hashtableobject.remove (key);
Remove all elements from the hash table: Hashtableobject.clear ();
Determines whether a hash table contains a specific key key:HashtableObject.Contains (key);
Traverse
foreach (DictionaryEntry item in Hashtable)
{
Item. Key;
Item. Values;
}
The most common use of generics is a generic collection, where namespace System.Collections.Generic contains some generic-based collection classes that use generic collection classes to provide higher type safety and higher performance, avoiding duplicate boxing and unpacking of non-generic collections.
Many non-generic collection classes have corresponding generic collection classes, the following are common non-generic collection classes and corresponding generic collection classes:
| Non-generic collection classes |
Generic collection Classes |
| ArrayList |
List<t> |
| HashTable |
Dictionary<t> |
| Queue |
Queue<t> |
| Stack |
Stack<t> |
| SortedList |
Sortedlist<t> |
single-column generic collection:list<object> list=new list<oibject> (); Traverse for (int i=0;i<list. count;i++) { Console.WriteLine (List[i]);} foreach (Object item in list) { console.writeline (item);} Double-row generic collection dictionary<object,object> dic=new dictionary<object,object> (); Traverse foreach (KeyValuePair< Object,object> item in DIC) {Console.WriteLine (dic. Key); Console.WriteLine (DIC. Value);} foreach (Object item in DIC. Keys) { console.writeline (item); console.writeline (Dic[item]. Value);} foreach (Object item in DIC. Values) { console.writeline (item);} Four. Method of deep Class 1. Constructor (1.) The method name is the same as the class name (2.) There is no return value (3.) The main object initialization work is 2. Syntax access modifier class name () { //method body} 3. Parameter constructor syntax access modifier class name ( Parameter list) { //method body} The implicit constructor system automatically assigns a parameterless constructor to the class. The overloaded parameterless and parametric constructs of constructors can be considered as method overloads. Method overloads (1.) method names are the same (2.) method parameter types are different or the number of parameters is different (3.) object interaction in the same class each class has its own features and capabilities, and we encapsulate them as properties and methods. Objects are interacted with by properties and methods. It can be considered that the parameters of the method and the return value of the method are transitive messages between objects. Personally, why does he call inter-object interaction? Because it is a property method interaction between objects. And the inherited polymorphic interface between classes. Six. Overview of initial knowledge inheritance and polymorphic inheritance 1. What is inheritance (1) redundant code for removing classes (2) Integrated concept 2.base keyword and protected modifier
public class person{protected String ssn = "111-222-333-444";p rotected string name = "Zhang San";p ublic virtual void GetInfo () {Console.WriteLine ("Name: {0}", name); Console.WriteLine ("Number: {0}", ssn);}} Class Employee:person{public String id = "abc567efg23267";p ublic override void GetInfo () {//Call the base class GetInfo method: base. GetInfo (); Console.WriteLine ("Member ID: {0}", id);}}
3. The subclass Constructor (1) implicitly calls the parent class constructor (2) to show that the use of inheritance, encapsulation, and polymorphism that call the parent class constructor is an important feature of object-oriented programming.
The class whose members are inherited is called the base class, also called the parent class, and the class that inherits its members is called the derived class, also called a subclass.
derived classes implicitly obtain all members except constructors and destructors for the base class.
derived classes can have only one direct base class, so C # does not support multiple inheritance , but a base class can have multiple direct derived classes.
inheritance can be passed .
private members have actually been inherited,
However, they cannot be accessed because private members can only be declared in their class or struct, so they do not appear to be inherited.
If a constructor with no parameters is in the base class
if a constructor with no arguments is in the base class, you can customize the constructor with parameters in the derived class
if the base class defines a constructor with parameters, then this constructor must be executed and implemented in the derived class, at which point we can use the Base keyword
if the base class of a derived class is also a derived class, then each derived class only has to be responsible for the construction of its direct base class, not the construction of the indirect base class.
and the order in which the constructors are executed begins with the topmost base class, until the last derived class ends.
the application of is a
since both SE and PM inherit employee, SE is a employee,pm is a employee.
the value of inheritance:
(1.) integration simulates real-world relationships, which emphasizes everything in OOP, which is in line with the way we think about object-oriented programming
(2.) Inheritance implements code reuse
(3.) integration makes the program structure clearer
polymorphic
solve problems with integration
virtual Method
the method that is decorated with the virtual keyword is called a virtual method. Virtual methods have method bodies
Grammar
access modifier Virtual return type method name ()
{
//Method body
}
overriding virtual methods
access modifier override return value type method name ()
{
//Method body
}
What is polymorphic
polymorphism literally means "multiple forms", which can have different interpretations and produce different results when the same action is used on different objects.
Implementing Polymorphic
(1.) Implementation method override
(2.) define a parent class variable
Seven. In-depth understanding of polymorphism
The principle of the Richter replacement
In a software system, subclasses can replace the location where the parent class appears, without any effect on the functionality of the software, known as the Richter substitution principle.
Subclasses can extend the functionality of the parent class, but cannot change the original functionality of the parent class. Subclasses can implement the abstract methods of the parent class, but cannot override the non-abstract methods of the parent class. Subclasses can add their own unique methods.
When a method of a subclass overloads a method of the parent class, the method's preconditions (that is, the parameter of the method) are more lenient than the input parameters of the parent class method.
When a method of a subclass implements an abstract method of the parent class, the post condition of the method (that is, the return value of the method) is stricter than the parent class.
It looks incredible, because we will find that in our own programming often violates the Richter scale replacement principle, the program still runs well. So everyone will have this question, if I do not follow the Richter scale replacement principle will have what consequences?
The consequence is that the odds of your code writing will increase dramatically.
For example: Father son=new son ();
There are two keywords in C # that can be used to withdraw the Richter scale substitution principle: the IS and as operators are to check whether the object and the specified type are compatible. The as operator is primarily used for type conversions between two objects.
Parent class type do arguments
Example: Give several classes first: 1. Parent class, vehicle class. Has a bunch of properties. 2. Car class, inherit the parent class. 3. Subway class, inherit the parent class. 4. Employee class. Staff take the transportation home! Employee Home method, parameter is the parent class object!
Then build a collection of employees and initialize the employees. Throw it in the collection. and = can use the collection of items point out the way employees go home to pass a subclass! This is the child class pointing to the parent class! The so-called Richter replacement principle!
Abstract classes and abstract methods
If a class is not associated with a specific thing, but simply expresses an abstract concept, just as a base class for its derived class, such a class is an abstract class, and when you declare a method in an abstract class, it is an abstract method when you add abstract.
The main differences between abstract and non-abstract classes:
• Abstract classes cannot be instantiated directly
• Abstract classes can contain abstract members, but not in abstract classes
• Abstract classes cannot be sealed or static
An abstract method is a method that is not implemented by adding the keyword abstract when defining a method to declare an abstract method.
Abstract method syntax
Access modifier abstract return value type method name ();
Note: The abstract method does not have a closed curly brace, but instead directly follows a ";" that is, it does not include the method body of the method execution logic!
Definition of abstract class
Syntax: Access modifier abstract class class name {}
Note: Abstract classes provide abstract methods that are only defined and how implementations are done by non-abstract subclasses of the abstract class.
Application of abstract classes and abstract methods
How to implement a subclass derived from an abstract parent class when deriving an abstract subclass from an abstract parent class, the subclass inherits all the characteristics of the parent class, including the abstract methods it does not implement. An abstract method must be implemented in a subclass, unless his subclass is also an abstract class.
Application of abstract classes and abstract methods
How to implement a subclass derived from an abstract parent class when deriving an abstract subclass from an abstract parent class, the subclass inherits all the characteristics of the parent class, including the abstract methods it does not implement. An abstract method must be implemented in a subclass, unless his subclass is also an abstract class.
Three major features of the face object
Encapsulation: Ensuring the integrity and security of the object's own data
Inheritance: To establish the relationship between classes, to implement code reuse, to facilitate the expansion of the system.
Polymorphic: The same method invocation can implement different implementations.
Eight. Extensible Markup Language XML
First, what is XML? What is the role?
L XML (extensible Markup Language) language is an Extensible Markup language. The extensibility is relative to HTML. Because XML tags are not predefined, users need to define their own labels.
L XML is designed to represent data, not to display it.
Ways to manipulate XML
Parsing XML files
public static void Main (string[] args)
{
XmlDocument doc=new XmlDocument ():
Doc. Load ("Engineer.xml");
XmlNode root=new XmlNode ();
foreach (XmlNode item in Doc. ChildNodes)
{
Switch (node. Name)
{
Case "id":
Console.WriteLine (node. InnerText);
Break
}
}
}
Displaying data with the TreeView
XmlDocument doc = new XmlDocument (); Doc. Load ("Beijing TV. xml"); XmlNode root = Doc. DocumentElement; Find the root node foreach (XmlNode item in root. ChildNodes)//traverse the child node {if (item. Name.equals ("tvprogramtable"))//The condition is whether the name of the node is "tvprogramtable" {foreach (XmlNode items In item. ChildNodes)//traverse the child node of the child node {tvprogram Tp = new Tvprogram (); Tp.playtime = Convert.todatetime (items["PlayTime"]. InnerText); Tp.meridien = items["Meridien"]. InnerText; Tp.path = items["Path"]. InnerText; Tp.programname = items["ProgramName"]. InnerText; Programlist1.add (Tp);//Bind to Collection}}}treenode Minenode = new Tre Enode (); Minenode. Text = "My TV station"; Bind TvList.Nodes.Add (Minenode); root node TreeNode root = new TreeNode (); Root. Text = "All Stations"; Bind TvList.Nodes.Add (root); ChannelManager Manager = new ChannelManager (); Manager. Resolvechannels (); list<channelbase> list = Manager. List; foreach (channelbase item in list) {TreeNode tn = new TreeNode (); Tn. Text = Item. ChannelName; Tn. Tag = Item; Root. Nodes.Add (TN); }
Nine. File operation
How to read and write files
Introduce a using. System.IO;
String Path=txtfilepath.text;
String Content=txtcontent.text;
if (path. Equals (null) | | Path. Equals (""))
{
MessageBox.Show ("The path of the file is not empty");
Return
}
Try
{
FileStream nyfs=new FileStream (path,filemode.create)
StreamWriter mysw=new StreamWriter (MYFS);
MYSW. Write (content);
MYSW. Close ();
Myfs. Close ();
MessageBox.Show ("write success");
}
catch (Exception ex)
{
MessageBox.Show (ex. Message);
}
File stream
Grammar
FileStream file Stream Object =new FileStream (string Filepath,filemode FileMode);
File Reader/writer
StreamWriter Writing Device
StreamWriter mysw=new StreamWriter ();
Solve garbled problems
FileStream myfs=new FileStream (Path,filemode.open)
StreamReader mysr=new StreamReader (Myfs,encoding.default);
Content=mysr.readtoend ();
Txtcontent.text=content;
File and directory Operations
File class and Directory class
Common methods for file classes
Exites (string path) to check whether the specified file exists
Copy () Copying files
Move () Moves the file
Delete () Remove file
Sample Small Explorer
Using system;using system.collections.generic;using system.linq;using system.text;using System.Threading.Tasks; Namespace chap09_ Explorer {class MyFile {public string FileName {get; set;} Public long filelength {get; set;} public string FileType {get; set;} public string FilePath {get; set;} }}using system;using system.collections.generic;using system.componentmodel;using System.Data;using System.Drawing; Using system.linq;using system.text;using system.threading.tasks;using system.windows.forms;using System.IO;using System.diagnostics;namespace chap09_ Explorer {public partial class Frmmain:form {public frmmain () { InitializeComponent (); } private void Frmmain_load (object sender, EventArgs e) {driveinfo[] di = Driveinfo.getdrives (); foreach (DriveInfo item in di) {TreeNode tn = new TreeNode (item. Name); Tn. Tag = Item. Name; TvList.Nodes.Add (TN); }} public void Bindinfo (TreeNode node) {try {Lvli St. Items.clear (); DirectoryInfo dir = new DirectoryInfo (node. Tag.tostring ()); directoryinfo[] dirs = dir. GetDirectories (); foreach (DirectoryInfo item in dirs) {TreeNode tn = new TreeNode (); Tn. Text = Item. Name; Tn. Tag = Item. FullName; Node. Nodes.Add (TN); } fileinfo[] fi = dir. GetFiles (); list<myfile> files = new list<myfile> (); foreach (FileInfo item in FI) {MyFile MF = new MyFile (); Mf. FileName = Item. Name; Mf. Filelength = Item. Length; Mf. FileType = Item. Extension; Mf. FilePath = Item. FullName; Files. ADD (MF); } foreach (MyFile item in files) {ListViewItem items = new ListViewItem ( Item. FileName); Items. SubItems.Add (item. Filelength.tostring ()); Items. SubItems.Add (item. FileType); Items. SubItems.Add (item. FilePath); LVLIST.ITEMS.ADD (Items); }} catch (Exception ex) {MessageBox.Show ("" +ex. Message); }} private void Tvlist_afterselect (object sender, TreeViewEventArgs e) { TreeNode node = This.tvList.SelectedNode; This. Bindinfo (node); } private void Lvlist_doubleclick (object sender, EventArgs e) {Process.Start (Lvlist.selecteditem S[0]. SUBITEMS[3]. Text); private void Copy Toolstripmenuitem_click (object sender, EventArgs e) {FOLDERBROwserdialog FBD = new FolderBrowserDialog (); DialogResult result = FBD. ShowDialog (); String sourcepath = Lvlist.selecteditems[0]. SUBITEMS[3]. Text; string despath = null; if (Result==dialogresult.ok) {Despath = FBD. SelectedPath; Despath + = "\" + lvlist.selecteditems[0]. Subitems[0]. Text; File.Copy (Sourcepath,despath); MessageBox.Show ("copy succeeded"); }} private void Delete Toolstripmenuitem_click (object sender, EventArgs e) {LvList.Items.Clea R (); String Deletepath=lvlist.selecteditems[0]. SUBITEMS[3]. Text; File.delete (Deletepath); MessageBox.Show ("delete succeeded"); } }}
This is how you can read what's on your hard drive after it's started!
All right, that's it. summed up here.
Personal summary in depth. NET platform and C # programming