base 关键字
见 msdn:http://msdn.microsoft.com/zh-cn/library/hfw7t1ce.aspx
this 关键字
见 msdn:http://msdn.microsoft.com/zh-cn/library/dk1507sz.aspx
一. 将class封装成dll
在vs tools中点击vs command prompt,输入如下命令:
csc /target:library 文件名.cs
注意: 文件路径要正确。
二. 将主文件和dll关联
csc /reference:dll文件名.dll 主文件名.cs
会生成 主文件名.exe 文件, 执行 exe文件,就可以看到运行结果。
三. 值传递和引用传递,输出参数的调用实例
运行结果:
i=0
j=1
k=1
四. 可变参数函数
五. 类型转换
六. 委托
(1)委托,委托链(静态)
(2). 匿名方法
(3)委托,委托链(动态 类)
(4) 实例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace delegate01
{
class DelegateSample
{
public delegate bool ComparisonHandler(int first, int second);
public static void BubbleSort(int[] items, ComparisonHandler comparisonMethod)
{
int i, j, temp;
for (i = items.Length - 1; i >= 0; i--)
{
for (j = 1; j <= i; j++)
{
if (comparisonMethod(items[j - 1], items[j]))
{
temp = items[j - 1];
items[j - 1] = items[j];
items[j] = temp;
}
}
}
}
public static bool GreaterThan(int first, int second)
{
return first > second;
}
public static bool AlphabeticalGreaterThan(int first, int second)
{
int comparison;
comparison = (first.ToString().CompareTo(second.ToString()));
return comparison > 0;
}
static void Main(string[] args)
{
int i;
int[] items = new int[5];
for (i = 0; i < items.Length; i++)
{
Console.Write("Enter an integer: ");
items[i] = int.Parse(Console.ReadLine());
}
BubbleSort(items, AlphabeticalGreaterThan);
for (i = 0; i < items.Length; i++)
{
Console.WriteLine(items[i]);
}
Console.ReadKey();
}
}
}
7 索引器
http://www.cnblogs.com/jarod99/archive/2009/01/09/1372453.html
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace basic01
{
class IndexClass
{
private Hashtable name = new Hashtable();
public string this[int index]
{
get { return name[index].ToString(); }
set { name.Add(index, value); }
}
public int this[string aName]
{
get
{
foreach (DictionaryEntry d in name)
{
if (d.Value.ToString() == aName)
{
return Convert.ToInt32(d.Key);
}
}
return -1;
}
set
{ name.Add(value, aName); }
}
}
class Program
{
static void Main(string[] args)
{
IndexClass b = new IndexClass();
b[500] = "Zhang San";
b[300] = "Li Si";
b[400] = "Wang Wu";
Console.WriteLine("b[500] = " + b["Zhang San"]);
Console.WriteLine("b[300] = " + b["Li Si"]);
Console.WriteLine("b[400] = " + b["Wang Wu"]);
b[600] = "Li Wu";
b[700] = "Wang Liu";
Console.WriteLine("b[600] = " + b[600]);
Console.WriteLine("b[700] = " + b[700]);
Console.ReadKey();
}
}
}