随笔分类 - C#
摘要:Abstract的问题:Abstract也许看上去优美,有一般methrod,virtual methord,或者abstract metho 1 abstract class Car 2 { 3 abstract public void tALK(); 4 public void Drive() 5 { 6 Console.WriteLine("WROOOOOOM"); 7 } 8 public virtual void TruboBosst() 9 {10 ...
阅读全文
摘要:C# API有这样的功能:View Code 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace ConsoleApplication5 7 { 8 abstract class Person 9 {10 private string _name;11 public string Name12 {13 get { return _name; ...
阅读全文
摘要:View Code 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace ConsoleApplication3 7 { 8 abstract class EvenNumberGenerator 9 {10 public void Run(int min, int max)11 {12 for (int i = min; i < max; i++)13 ...
阅读全文
摘要:View Code 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace ConsoleApplication2 7 { 8 abstract class Item 9 {10 public abstract void Dispaly();11 public abstract void Use();12 }13 class Chair : Item14 {15...
阅读全文
摘要:Virtual memebers:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication2{ class Person { public string Firstname { get; set; } public string SecondName { get; set; } public virtual void Display() { C...
阅读全文
摘要:我们知道,一个类的方法从调用方式上可以分为“静态方法”与“非静态方法”(实例方法)。在.net框架中,也有很多这种公共静态方法。现在我想讨论一下,一个类为什么要提供静态方法以及在什么时候应该提供静态方法。静态方法与非静态方法最明显的区别就是如果某个方法是公共静态的,那么可以直接 通过类名.方法名的方法来调用,而公共实例方法则需要事先实例化对象,然后才能调用。很多人认为静态方法来速度上、在内存占用比值上要比实例方法快和多, 这一点我不认同。方法执行的快与慢在同等条件下主要决定于所要进行的操作,而静态方法要比实例方法占用更多的内存这一点更是毫无根据。一个类型加载的时 候,该类的所有的方法都会被加载
阅读全文
摘要:C# Object Clone WarsCloning C# objects is one of those things that appears easy but is actually quite complicated with many "gotchas." This article describes the most common ways to clone a C# object.Shallow vs. Deep CloningThere are two types of object cloning: shallow and deep. A shallow
阅读全文
摘要:初识枚举 1、枚举其实可以理解为一个恒量的结合,又或者可以认为它是一种类型。比如以下枚举定义:1 publicenum MicrosoftTechnology2 {3 CSharp,4 ASPNETMVC,5 SQLServer,6 WCF,7 SilverLight,8 }此枚举默认为int型,当然我们可以根据需要指定枚举的数据类型。比如 public enum MicrosoftTechnology: long{....} 等。MicrosoftTechnology枚举int值分别为 Csharp:0;ASPNETMVC:1;SQLServer:2;WCF:3;Silv...
阅读全文
摘要:Char ArrayChar Array储存string data。有两个方法建立StringBuilder和Character array【Character array】用来存储character data,比如字母和数字好处:array element被储存在内存中的一块,避免了存储于分开的对象所带来的内存消耗。Char是基本的变量类型,她不是存储reference而是存储在内存本身。建立char array:using System;class Program{ static void Main() { char[] array1 = { 's', 'a'
阅读全文
摘要:Array: (需要一队数据,他们由index控制)1:内存中的样子2:Array定义方法:int[] myArrays = new Int[4];myArrays[0] = 100;myArrays[1] = 200;myArrays[2] = 300;myArrays[3] = 200;orint[] myArrays = {100,200,300,200};string[] myStrings = {"one", "two", "three","four"};3:Multi-Array定义方法:int[,]
阅读全文
摘要:Class:class是blueprint,用来描述What kinds of data the object holds and works with, What the object can do what its functionality isUsually, your C# programs will define their own classes, as well as use the classes that are provided by the .NET frameworkClass define two major things(Fields and Properties
阅读全文
摘要:C#的层级:Variables:C#中使用Variable必须先declare变量的类型type nameint myNumber;string message;Scope: 1:注意scope的使用范围: intmyFunction(){ intx=10; x++;//ok for(inti=0;i<10;i++) { inty=x+20;//ok //othercode... } x++;//ok y+=20; //erroryisnotavailablehere} 2:父子scope或者同一scope里不可以重新声明同一个变量:Ca...
阅读全文
摘要:在C#建立Event有5步:一: 最外面声明Delegate:delegate void MyEventHandler (int x, string y);二:建立含有私有类的Event(被别人使用):class MyClass(){ ... public event MyEventHandler MyEvent; ...}三:建立class的实例(Subscribing to an event)MyClass obj = new MyClass();四:Listening to the event:subscribe event: obj.MyEvent += handlerFun...
阅读全文
摘要:1: Declare the Delegatedelegate int DelegateName (int i, string s);Define return name of Delegate delegate need to be handle2: Use DelegateDelegateName func = someFunction就 像使用其他任何类型的name一样(int age = something),这里我们declar a 变量func(类型为DelegateName).接下来assign someFunction(这里的function...
阅读全文
摘要:委托定义委托的语法和定义方法比较相似,只是比方法多了一个关键字delegate。 我们都知道方法就是将类型参数化,传输某种类型的参数到方法中,而委托是将方法参数化,就是将方法作为一个参数传到一个委托中。1: 委托的声明:public delegate void MyDelegate ();访问修饰符 delegate 返回类型 委托名 参数列表委托传入方法,方法传入变量委托的返回值可以是任何类型,比如:string,或者int可以放若干参数作为输入注意参数列表的形参要和实参一致*委托只要定义就可以了,不关心其功能如何实现,具体功能实现由注册的方法完成。不像...
阅读全文

浙公网安备 33010602011771号