 |
| C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

May 2nd, 2008, 06:52 AM
|
|
Authorized User
|
|
Join Date: Apr 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
foreach with two lists
Hey, I'm trying to make a foreach with two lists
But how do I do what, I tryed here, and I'm aware of this error:
en_flaske.PropertyFlaskeID == temp_flasker because temp_flasker are a list
private void button2_Click(object sender, EventArgs e)
{
//makes temporary list
List<string> temp_flasker = new List<string>();
foreach (object i in checkedListBox12.CheckedItems) temp_flasker.Add(i.ToString());
//makes a reservation
Reservering ny = new Reservering((label12.Text), (dt));
//The reservations are added to the "Flaske" which are "true" and where the ID match the ID from the temporary list
foreach (Flaske en_flaske in Flaskeliste)
if ((en_flaske._flaskeledig(dt)) == true && en_flaske.PropertyFlaskeID == temp_flasker/*here are the error*/);
{
en_flaske.Add(ny) ;
}
}
|
|

May 2nd, 2008, 07:37 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
temp_flasker is a List, and you are trying to compare it to what I assume is a string?
I assume you want to know if the list Contains the Flaske ID?
temp_flasker.Contains(en_flaske.PropertyFlaskeID) will return true if this is the case.
/- Sam Judson : Wrox Technical Editor -/
|
|

May 2nd, 2008, 07:42 AM
|
|
Authorized User
|
|
Join Date: Apr 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hallo
I want to add a reservation to the right "flaske" in the Flaskelist
|
|

May 2nd, 2008, 07:44 AM
|
|
Authorized User
|
|
Join Date: Apr 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
So there are two conditions which should be true, for me to add the "flaske"
1. It should be free
2. It shall be on the temp_list
|
|

May 2nd, 2008, 07:46 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
But surely temp_flasker is a List, and could contain more than 1 'flaske'.
If it only contains 1 value then the above will still work however.
/- Sam Judson : Wrox Technical Editor -/
|
|

May 2nd, 2008, 08:15 AM
|
|
Authorized User
|
|
Join Date: Apr 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
ok, so do you know how I can code it, so the code will work when I want to find en_flaske.PropertyFlaskeID which have the same ID as a string in the temp_flasker?
|
|

May 2nd, 2008, 08:31 AM
|
|
Authorized User
|
|
Join Date: Apr 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I got this error:
Error 4 Operator '==' cannot be applied to operands of type 'string' and 'System.Collections.Generic.List<string>'
|
|

May 2nd, 2008, 09:18 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
Yes, I wrote it in my previous post.
/- Sam Judson : Wrox Technical Editor -/
|
|

May 2nd, 2008, 09:29 AM
|
|
Authorized User
|
|
Join Date: Apr 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
ok, but the list contains more than one "flaske".. so do you know what I could I do instead?
|
|

May 2nd, 2008, 10:07 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
If your 'checked list' contains more than 1 'flaske' then I don't know how you are meant to know which one to use.
/- Sam Judson : Wrox Technical Editor -/
|
|
 |