1
//记号
//记号
posted @ 2006-06-17 21:56 瓶子 阅读(90) 评论(0) 编辑
RIMBAUD,20岁后失业,................................Asp.Net,MONO |
2006年6月17日 #
2006年6月16日 #
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1

{
/**//// <summary>
/// Refere ninputer's blog
/// </summary>
class Class2
{
private class myType<t>
{ }
delegate void DelegateType();



static void Main()
{
/**//*
* 获得一个封闭构造类型(closed constructed type)的Type对象?
* 假设有类型: private class myType<t> { }
*/
Console.WriteLine(typeof(myType<>).ToString());
/**//*
* 如何从构造类型的Type对象生成泛型类型的Type对象?
* Type类的新增方法GetGenericTypeDefinition可以做到。
*/
DelegateType delegateInstance = delegate()
{
Type cy = typeof(List<int>);
Type gy = cy.GetGenericTypeDefinition();
Console.WriteLine(gy.ToString());
};

/**//*如何获取类型参数的Type对象?
*泛型类型的T, U等类型参数,以及运行中的实际取值,都是可以从Type对象获取的
*/
delegateInstance += delegate()
{
Type cy = typeof(List<int>);
Type[] gy=cy.GetGenericArguments();
for (int i = 0; i < gy.Length; i++)
{
Console.WriteLine(gy[i].ToString());
}
};
/**//*从泛型类型Type对象生成构造类型的Type对象。
*通常可以用来从一种构造类型生成另一种构造类型
*/
delegateInstance += delegate()
{
Type cy = typeof(List<int>);
Type gy = cy.GetGenericTypeDefinition();
Type ny = gy.MakeGenericType(typeof(string));
Console.WriteLine(ny.ToString());
};
/**//*
* 如何取一个开放构造类型(open constructed type)的Type对象?
* 开放构造类型是最难处理的一个,因为他们的类型参数已经指定,但没有指定为具体类型,
* 而是指定为其他泛型类型的类型参数。这种类型在进行反射重载选取以及反射发出(Reflection Emit)
* 操作的时候尤为重要。我们的手法就是,先从宿主泛型类型的定义中获取类型参数的类型,然后再建造出开
* 放构造类型。这里,我们获得List<T>的构造函数的参数,IEnumerable<T>的类型,注意这里的T是List<T>所定义的,
* 而不是泛型IEnumerable<T>自己的类型参数
*/
delegateInstance += delegate()
{
Type cy=typeof(List<>);
Type typeParm1 = cy.GetGenericArguments()[0];
Type tienum = typeof(IEnumerable<>);
Type tienumOpen = tienum.MakeGenericType(typeParm1);
// 只有用这种方法获得开放构造类型
//你才能用这个语法获得真正想要的构造函数定义
//因为构造函数定义里IEnumerable(Of T)是一个开放构造类型
System.Reflection.ConstructorInfo c=cy.GetConstructor(new Type[]
{tienumOpen});
Console.WriteLine(c.ToString());
};

delegateInstance.Invoke();
Console.Read();
}
}
}
2006年5月3日 #
<html>
<head>
<script>
function count()

{
var obj=document.getElementById("myHide");
if (obj)
{
var c=obj.value;
obj.value=c+1;
}
}
function onBtn()

{
var obj=document.getElementById("myHide");
if (obj)
alert("第"+obj.value.length+"次加载!");
}
</script>
</head>
<body onbeforeunload="count();">
<input type="hide" id="myHide" value="0">
<input type="button" id="myBtn" value="第几次加载" onClick="onBtn()">
</body>
</html>2006年5月2日 #
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1

{
class Program
{
/**//// <summary>
/// 函数:给定一个集合,求出其所有子集合
/// </summary>
private static List<string> printList(string[] arr, int num)
{
if (num < 0)
{
List<string> reto = new List<string>();
reto.Add("");
return reto;
}
else
{
List<string> ret = printList(arr, num - 1);
List<string> addRet = new List<string>();
ret.ForEach(delegate(string x)
{ addRet.Add(x +" "+ arr[num]); });
ret.AddRange(addRet);
return ret;
}
}
static void Main(string[] args)
{
//演示
string[] arr =
{ "a", "b", "c"};
List<string> ret = printList(arr, 2);
ret.ForEach(delegate(string x)
{ Console.WriteLine(x); });
Console.Read();
}
}
}2006年4月30日 #
2006年4月26日 #
2006年3月22日 #
2004年10月21日 #