One of the C # Learning notes (Basic, class, Function,array, collection

Source: Internet
Author: User
Tags foreach array arrays implement interface sort
I recently learned the C # Programming course, now summarize the notes as follows, there is no system collation, is the lesson to remember notes, the following parts of the majority of the program, because these notes have not been done, so many code without detailed comments, if there is time, I will do the system of notes, There is no mention of the basic grammatical introduction, I hope you understand:

Basic:
Use out, do not give i,j assign initial value
int i,j;
F (out I, out j) {}
Using, automatically destroy objects outside of parentheses
using (Font Thefont = = new Font ("Ariel", 10.0f)) {}
Constants
const int i = 32;
Enumeration
Enum E {a=5,b=8}
int i = (int) e.a;
Turn buff data to string
Encoding.ASCII.GetString (Buff, 0, Bytesread)
Read data
string s = Console.ReadLine ()
int j= Convert.ToInt32 (s);
Get textbox value and convert to double
Double left = double. Parse (TextBox1.Text);
Application.doevent (); This'll let the app deal with event
Array
A[] A = new a[5]; A[0]to A[5] is null
int[] arr = new int[2] {1,2}
Int[] arr = {2,3,4,5}
foreach (A In arr_a) {}
for (int i=0; I<arr. Length; i++) {}
Rectangular Arrays
int[,] Rectarray = new int[4,5]
int[,] arr = {{1,2,3,4},{1,2,3,4}{1,2,3,4}}; Init
Jagged array, array containing arrays, unequal lengths of each dimension
Ja[0]. Length is length of ja[0]
int [[] ja = new int[4][];
Using params transfer an array to a function
Using f (1,2,3,4) to call the function
F (params int[] values) {
foreach (int[] A in values) {}
}
Collection Interface:
Indexers:
Define a indexers
Public Myclass This[int offset] {get{};set{}}
Call it
Employee Joe = bostonoffice["Joe"];
IEnumerable:
Return a IEnumerator object
GetEnumerator ()
IEnumerator:
Reset () {}
Current () {}
MoveNext () {}
IComparable:
Class Inherit IComparable interface
Implement CompareTo () method
CompareTo ()
ArrayLists:
Count get number of elements
Add () Add an Object
Clear () Remove all objects
Reverse () Reverse Order of elements
Sort () sort the elements
function
Default by value
f (int x) {}
by reference
f (ref int x) {}
Class
Access:
Public, private, protected, internal, protected internal
This, the static//static member must is init in class
Inherited
Class A:b {}
Polymorphic
Virtual,override
Init object
Employee EMP1 = new Employee ();

First implicitly converts 3 to Roman
Roman R4 = r1 + 3;
First explicitly convert 7.5 to Roman
Roman R5 = r1 + (Roman) 7.5;

operator overload, return int, and then use an implicit conversion
public static Roman operator+ (Roman L, Roman R)
{
return (L.val+r.val);
}
Explicit conversions
public static explicit operator Roman (float val)
{
return new Roman (Val);
}
Implicit conversions
public static implicit operator Roman (int val)
{
return new Roman (Val);
}
Properties, note case
public int Age {
get {return age;}
set {age = value;}
}

Interface
Interface methods must is implement in class
Public interface IA {}
is test class inherits from interface
If (A is IA) {IA c = (IA) A;}
As test class inherits from interface
IA C = A as IA;
if (c!= null) {}
Interface Properties
Pubiic Interface Iaa:ia
{
float F{get;set;}
}
Mutiface Interface Inheritance
public class C:ia,




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.