Home > Net >  A question about template method
A question about template method

Time:10-07

I want to do in the template method in the unity of comparison,
 
Public static T [] DeleteItem (T [] list, T v)
{

Int c=list. Length;

For (int I=0; I & lt; C; I++)
{
If (a list [I]==v)
{
T [] list2=new T/c - 1;
For (int j=0; J & lt; i; J++)
{
List2 [j]=list [j];
}
For (int j=I + 1; J & lt; C; J++)
{
List2 [1]=list [j];
}
Return list2;
}
}
return list;
}



However, in the code above the if (the list [I]==v) this is an error,
error CS0019: Operator `=='always be applied to operands of type ` T' and ` T '

Where T: System. The Object does not allow, where T: Unity. The Object can make equal, greater than the less-than or not, and the System. The string can't turn Unity. The Object

This is there any way can make the template function used in & gt;==& lt; ?

CodePudding user response:

With the object. ReferenceEquals Equals or CompareTo (realized ICompareable interface), such as
Or use==expression tree dynamic invocation

CodePudding user response:

Types of uncertainty, so she could not compare, you can use the attributes in the GetValue (),

CodePudding user response:

Because there is no operator overloading,
  •  Tags:  
  • C#
  • Related