C#程序集Assembly

上传人:飞*** 文档编号:44839802 上传时间:2018-06-14 格式:DOC 页数:3 大小:83KB
返回 下载 相关 举报
C#程序集Assembly_第1页
第1页 / 共3页
C#程序集Assembly_第2页
第2页 / 共3页
C#程序集Assembly_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《C#程序集Assembly》由会员分享,可在线阅读,更多相关《C#程序集Assembly(3页珍藏版)》请在金锄头文库上搜索。

1、C#程序集程序集 Assembly一、Assembly1.创建一个应用程序域 application domainAppDomain d = AppDomain.CreateDomain(“MyDomain“);Console.WriteLine(AppDomain.CurrentDomain.FriendlyName);/获取当前应用程序域的友好名称Console.WriteLine(d.FriendlyName);/获取应用程序域的友好名称图片 1当前程序所在的项目就是:Csharp,在资源管理器中还可以看到一个进程:图片 22.利用 AppDomain 类来执行程序集if (AppDom

2、ain.CurrentDomain.FriendlyName != “MyAppDomain“)/如果当前应用程序域的名称不是 MyAppDomain/那么创建对象的应用程序域AppDomain domain = AppDomain.CreateDomain(“MyAppDomain“);domain.ExecuteAssembly(“Csharp.exe“, null, args);/使用指定的参数运行指定文件中的程序集3 获取或设置 AppDomain 类的数据setData(),getData()这两个方法来设置和获取数据AppDomain d = AppDomain.CreateDom

3、ain(“MyDomain“);Console.WriteLine(AppDomain.CurrentDomain.FriendlyName);ArrayList list = new ArrayList();list.Add(“alive“);list.Add(“silver“);list.Add(“dog“);list.Add(“Ftp“);d.SetData(“para“, list);/将制定的值赋值给应用程序域的属性foreach (string s in (ArrayList)d.GetData(“para“)/ 获取存在当前应用程序域中的值Console.WriteLine(“y

4、ou will see“ + s);程序运行结果如下:图片 34.显示应用程序域中的所有程序集要实现这个,就必须增加引用:using System. Reflection;映射AppDomain d = AppDomain.CreateDomain(“MyDomain“);Console.WriteLine(AppDomain.CurrentDomain.FriendlyName);Console.WriteLine(“in “ + d.FriendlyName);/Assembly myass = d.GetAssemblies();/获取当前应用程序域中所有程序集foreach (Asse

5、mbly ass in myass)Console.WriteLine(“its name:“ + ass.GetName().Name);Console.WriteLine(“its version:“ + ass.GetName().Version);/获取程序集的名称和版本图片 4这里显示了当前 Csharp 程序运行时候所涉及到的程序集。在前面的学习过程中,多次介绍到了命名空间,namespace;在 C#的编程过程中,如果没有引用某一个命名空间,那么很多相关的类就不能创建对象,或者在程序的运行过程中会出现编译错误.在 OOP 程序设计过程中,一个类都由方法和属性,字段组成;那么一个命名空间则是由一个以上的类组成,在这里命名空间中有许多内置的类可以调用。现在来看下一个简单的命名空间:图片 5那么我们在另外一个文件中可以引用这个命名空间下的类了。Using Csharp;Csharp.Program pr=new Csharp.Program();这样就完成了命名空间的设计和引用。

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号