Click here to Skip to main content
15,883,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a list like
C#
IList<BackPlanes> backplanes =
                  panel.Items.Where(x => x is BackPlanes).OrderBy(x => x.Index).Cast<BackPlanes>().ToList();


backplanes = backplanes - 1;

I am getting an error like Operator - cannot be applied to operands of type System.Collections.Generic.IList<domain.generatecontrols.backplanes> and int.

C#
foreach (KeyValuePair<double, double> drop in DrawFrame)
                                     {
                                        if (backplanes.Count <= 0) break;

                                         Shape framecabl = panelSheet.Drop(frameCable, drop.Key, drop.Value);
                                         framecabl.Text = terminalBoxSummary.ToString();
                                         backplanes = backplanes-1;
                                     }
Posted
Updated 30-Dec-14 22:14pm
v3
Comments
Snesh Prajapati 31-Dec-14 4:06am    
what you want to do by doing that minus operation ?
chandra sekhar 31-Dec-14 4:07am    
if (backplanes <= 0) break;
[no name] 31-Dec-14 4:19am    
Here you can not use the minus operator as the left argument is a list of data and right argument is an integer. As Snesh mentioned you can get the length of the list and you can use the minus operator there.
BillWoodruff 31-Dec-14 4:56am    
I think you need to re-think your logic here: why create a List of BackPlanes only to destroy it ?

1 solution

As we discussed, then you should write:
C#
if (backplanes.Count <= 0) break;


To remove first element you can use (instead of "backplanes = backplanes-1;")
C#
backplanes.RemoveAt(0);

//or use following code:
for(int i=0; i< backplanes.Count; i++ )
{
// your operations here....
}


For more: http://msdn.microsoft.com/en-us/library/5cw9x18z.aspx[^]
 
Share this answer
 
v4
Comments
chandra sekhar 31-Dec-14 4:11am    
I have updated the question.
Snesh Prajapati 31-Dec-14 4:19am    
I undated the solution....that will keep removing first element of existing list.
chandra sekhar 31-Dec-14 4:23am    
Its not like removing the first element if the backplanes is 0 it has to break,decreasing the counter.
Snesh Prajapati 31-Dec-14 4:26am    
the better use "for" loop based on backplanes.Count. I will provide the code in solution.

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