如何使用扩展方法对 C# 中的所有数据类型进行自定义验证
How to make custom validation for all datatype in c# using extension methods
嗨,我想使用 C# 扩展方法对所有数据类型进行自定义 conman 验证,请给我一些想法和一些示例?
谢谢
我想你对c#中的变量一无所知。
请在 link 中查看更多关于变量的信息,因为所有类型都继承自 System.Object
enter link description here
例如,这段代码可能会解决你的问题,但我不明白是为了什么...
public static class Test
{
public static bool UserCheck(this object a)
{
return a != null;//ha-ha
}
}
public class SomeProgramm
{
public void main()
{
int a = 0;
a.UserCheck();
object b = new object();
b.UserCheck();
}
}
嗨,我想使用 C# 扩展方法对所有数据类型进行自定义 conman 验证,请给我一些想法和一些示例?
谢谢
我想你对c#中的变量一无所知。
请在 link 中查看更多关于变量的信息,因为所有类型都继承自 System.Object enter link description here
例如,这段代码可能会解决你的问题,但我不明白是为了什么...
public static class Test
{
public static bool UserCheck(this object a)
{
return a != null;//ha-ha
}
}
public class SomeProgramm
{
public void main()
{
int a = 0;
a.UserCheck();
object b = new object();
b.UserCheck();
}
}