Click here to Skip to main content
15,893,337 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have the following code written in one of the class

C#
class LD_L_Entry
{
public static List<LD_L_Entry> operator + (List<LD_L_Entry> A,List<LD_L_Entry> B)
{
   /*code*/
}

}


when i build the project I get the following error
One of the parameters of a binary operator must be the containing type

Googled it but was not able to find the correct solution for it
Posted
Updated 20-Mar-12 2:56am
v2

This code looks ok. I built it separately and did not get any error.
Try doing a clean and the build the solution again.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 20-Mar-12 16:11pm    
True, a 5.
--SA
Abhinav S 20-Mar-12 22:29pm    
Thank you SA.
bsb25 21-Mar-12 0:52am    
I am using .NET 3 framework.even i tried to build it seperately but am still getting the same error.As from the article mentioned in the link below,This wont work.
Monjurul Habib 21-Mar-12 3:41am    
5!
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 20-Mar-12 16:12pm    
Right article to read, my 5. As Abhinav correctly noted, the OP's code should not show this error: both operands are already of the type of declaring type.
--SA
Your class is clearly NOT the same type as either of the parameters in the operator. By design you cannot extend or override operators for the System defined Types of the .NET Framework. In your case 'List'.

I wouldn't mind but others seriously do[^]. C# is used a lot in platform development and arguments differ from those of a scripting language in a FastCGI environment.

Anyways, try:


C#
void Main()
{
    var x = new LD_L<string>(){"a"};
    var y = new LD_L<string>(){"b"};
    var z = x+y;
}
class LD_L<LD_L_Entry> : List<LD_L_Entry>
{
    public static LD_L<LD_L_Entry> operator + (LD_L<LD_L_Entry> A,LD_L<LD_L_Entry> B)
    {
        /*code*/
        Console.WriteLine("foo and bar were pluzz-oped: " + A.GetType().ToString() + "+" + B.GetType().ToString());
        return null;
    }
}


Result:
foo and bar were pluzz-oped: UserQuery+LD_L`1[System.String]+UserQuery+LD_L`1[System.String]

Note:
You do not need .GetType().ToString(), .ToString() would suffice.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900