“----------ASP.Net+Android+IOS开发、Net培训、期待与您交流!----------”
1.新建一个类StringComponent.cs
using System;
namespace ComponentCS
{
public class StringComponent
{
public StringComponent()
{
StringSet = new String[]
{
"C# String0",
"C# String1",
"C# String2",
"C# String3",
};
}
private string[] StringSet;
public event EventHandler Modified;
public int StringLength
{
get { return StringSet.Length; }
}
public void Modify(int index, string value)
{
if (index < 0 || index >= StringSet.Length)
{
throw new IndexOutOfRangeException();
}
StringSet[index] = value;
OnModify();
}
private void OnModify()
{
EventArgs e = new EventArgs();
if(Modified!=null)
{
Modified(this, e);
}
}
public string GetString(int index)
{
if (index < 0 || index >= StringSet.Length)
{
throw new IndexOutOfRangeException();
}
return StringSet[index];
}
}
}
3.使用csc.exe(C:\Windows\Microsoft.NET\Framework\)将上面的cs文件编译成dll
4.测试
using ComponentCS;
namespace WebApptest
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
StringComponent sc = new StringComponent();
Response.Write(sc.StringLength);
}
}
}