gpt4 book ai didi

c# - 在函数中验证自定义类的类型

转载 作者:行者123 更新时间:2023-11-30 14:17:20 26 4
gpt4 key购买 nike

在 C# 中,我有一个可以传递 List 参数的公共(public)函数,T 是一个自定义类。该函数可以通过不同的 T 类。如何在每种情况下验证T的类型?

public static List<T> ConvertData(List<T> oldDatas)
{
//I will analyze the object T,
//but now i don't know how to verify the type of T,
//with T can change,
//example maybe T is T1 class,or T2 class..
}

感谢我的愚蠢问题。

最佳答案

这是针对 C# 的

Type gt = typeof(T);

为 java 检查这个:Get generic type of java.util.List

关于c# - 在函数中验证自定义类的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6185688/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com