一.将class封装成dll
在vs tools中点击vs commandprompt,输入如下命令:
csc /target:library文件名.cs
注意: 文件路径要正确。
二. 将主文件和dll关联
csc /reference:dll文件名.dll 主文件名.cs
会生成主文件名.exe 文件, 执行 exe文件,就可以看到运行结果。
三.值传递和引用传递实例
using System;
namespace Method21
{
classProgram
{
static void ValueMethod(inti)
{ i++; }
static voidReferenceMethod(ref int i)
{ i++; }
static void Main(string[]args)
{
int i = 0;
int j = 0;
ValueMethod(i);
ReferenceMethod(ref j);
Console.WriteLine("i={0}",i);
Console.WriteLine("j={0}",j);
Console.ReadKey();
} }}
运行结果:
i=0
j=1
1. 类、对象、接口、继承 实例:
usingSystem;
using System.Collections.Generic;
using System.Text;
namespace _9ex01
{
publicabstract class MyBase
{
}
internalclass MyClass : MyBase
{
}
publicinterface IMyBaseInterface
{
}
internalinterface IMyBaseInterface2
{
}
internalinterface MyInterface : IMyBaseInterface,IMyBaseInterface2
{
}
internalsealed classMyComplexClass : MyClass, MyInterface
{
}
class Program
{
static void Main(string[] args)
{
MyComplexClass myObj = new MyComplexClass();
Console.WriteLine(myObj.ToString());
Console.ReadKey();
}
}
}
2. 索引器,数组,函数重载
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace indexer
{
classArrClass
{
private readonly string name;
public ArrClass(String name)
{ this.name = name; }
public string Name
{
get { return name; }
}
}
classIndexClass
{
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);