|
I have classes as these below,
and I have myList List<cost>,
myList.Add(new Materials),
myList.Add(new PlannedOperation)
I have to implement searching in List<cost>, but I do not know exactly how.
For example I want to find: Cost where type of cost is Materials and orderNumber = "000001"
or Cost where type of cost is PlannedOperation and value > 50000
I should have in the result List<cost>, or maybe List<materials>, List<plannedoperation> ...?:/
Thanks for Your help.
public abstract class Cost
{
private Int32 id;
public Cost()
{
}
public abstract override string ToString();
public Task Task
{
get
{
return this.m_task;
}
set
{
this.m_task = value;
}
}
public Int32 Id
{
get
{
return this.id;
}
set
{
this.id = value;
}
}
public abstract double Value
{
get;
set;
}
}
public class Materials : Cost
{
private string name;
private string description;
private double value;
private DateTime orderDate;
private DateTime realizationDate;
private string orderNumber;
public Materials()
: base()
{
}
public override double Value
{
get
{
return this.value;
}
set
{
this.value = value;
}
}
public string OrderNumber
{
get
{
return this.orderNumber;
}
set
{
this.orderNumber = value;
}
}
}
public class PlannedOperation : Cost
{
private double hours;
public PlannedOperation()
{
}
public double Hours
{
get
{
return this.hours;
}
set
{
this.hours = value;
}
}
public override double Value
{
get
{
return this.hours * this.m_OperationMachine.Operation.CC.SearchRate
(this.Task.AddDate.Year.ToString()).Value;
}
set
{
}
}
}
|
|
|
|
|
Have a look at List.FindAll[^], I think that'll satisfy your requirements.
|
|
|
|
|
This is the most probably comfortable. Thanks.
|
|
|
|
|
You're welcome.
|
|
|
|
|
How about loop[^] this list, switch[^] the type, cast[^] the object, then compare[^] the values.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
I was thinking about this, but loop by 100000 elements? Is this the good idea? I'm looking for something more effective.
modified on Friday, May 22, 2009 9:45 AM
|
|
|
|
|
arturw82 wrote: Loop by 100000 elements? I look for something more effective
What do you mean more effective? you mean one line of code that does all the work for you, well that's not possible. you are passing different types into the list and you want to compare different values based on the type that is in the list.
How do you expect to search a list without check all the items
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Something quicker in the working.
I am novice, that is why I ask. There are solutions or practice maybe about which I do not know.
|
|
|
|
|
What's more basic than a for loop, a switch statement, and an if statement??? If you can't cope with them then you need to go back a step - not look for another alternative.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
|
|
I invented something like this. But I will check Your solution if will be some difference in efficiency...
List<Cost> aa = l1.FindAll(c => (c is Materials && ((Materials)c).OrderNumber == "9999999"));
|
|
|
|
|
|
you can't. WebBrowser is a WebBrowser, Internet Explorer is an application
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Hi All,
In my application i want to read the row content of an excel file as html text (for getting the font and style). If anybody knows please help me....
Regards,
Prajilal
|
|
|
|
|
Save your excel file as an HTML document, excel has had the ability to export as HTML for a while.
|
|
|
|
|
Hello Friends..
I am using a datagridview which have a checkbox column.there is a delete button on the form.i want that when i click the delete button and none of the check box is checked(true). it will simply display a message that "Firrst select a row".
|
|
|
|
|
Loop through each row in the datagridview and check for the ones where the value of the cell with the checkbox == true. If there are none then be rude to the user and ask him/her to check 1 or more item.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
suppose there are 20 rows and one is checked and i put the code (checkbox=true)with in the loop then 19 times it display "Please Select a Row". and i think its not good.
|
|
|
|
|
Thinking is not one of your strong suits is it.
Loop the data rows
count the checked items
ask for confirmation to delete n# items checked
OR call the user an idiot and ask them to check 1 or more item.
If you can't work these things out you are really going to struggle as a developer!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
ok ok now i understand...
i am a fresher,i have no idea about that...
|
|
|
|
|
my apps icon show in system tray. whenever i am closing my apps then that icon still showing in system tray.so please tell me is it possible to refresh system tray by c# language or by calling Win32 API from c#. please help me with sample code if it is possible.
tbhattacharjee
|
|
|
|
|
Hi,
I wrote an article on that subject.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I've only ever done this once but IIRC you put the notifyicon into the tray, when closing the app you need to remove it before closing the app. Use the mainform.onclosing event to remove the icon.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
correct, unless your app crashes or you abort a debug run. Then the icon stays put.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|