代码
using System;
class A<T>{
T mb = default(T);
public void set(T t){
mb = t;
}
public T get(){
return mb;
}
}
class B{
public int a = 5;
}
public class Fanxing{
public static void Main(){
Console.WriteLine("hello word");
B b = new B();
A<B> ab = new A<B>();
ab.set(b);
B b2 = ab.get();
Console.WriteLine(b2.a);
}
}
本文探讨了使用C#中的泛型类进行对象属性传递的方法。通过实例演示了如何定义和使用泛型类A<T>来封装类型T的对象,并通过set和get方法实现对象属性的设置和获取。此外,还展示了如何在主函数中创建泛型类的实例,设置并获取B类对象的属性。
912

被折叠的 条评论
为什么被折叠?



