Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
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
 
Old May 2nd, 2008, 06:52 AM
Authorized User
 
Join Date: Apr 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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) ;

            }
}

 
Old May 2nd, 2008, 07:37 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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 -/
 
Old May 2nd, 2008, 07:42 AM
Authorized User
 
Join Date: Apr 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hallo

I want to add a reservation to the right "flaske" in the Flaskelist




 
Old May 2nd, 2008, 07:44 AM
Authorized User
 
Join Date: Apr 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default


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

 
Old May 2nd, 2008, 07:46 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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 -/
 
Old May 2nd, 2008, 08:15 AM
Authorized User
 
Join Date: Apr 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?





 
Old May 2nd, 2008, 08:31 AM
Authorized User
 
Join Date: Apr 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I got this error:
Error 4 Operator '==' cannot be applied to operands of type 'string' and 'System.Collections.Generic.List<string>'


 
Old May 2nd, 2008, 09:18 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Yes, I wrote it in my previous post.

/- Sam Judson : Wrox Technical Editor -/
 
Old May 2nd, 2008, 09:29 AM
Authorized User
 
Join Date: Apr 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok, but the list contains more than one "flaske".. so do you know what I could I do instead?

 
Old May 2nd, 2008, 10:07 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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 -/





Similar Threads
Thread Thread Starter Forum Replies Last Post
foreach confusion stokerfed C# 2 June 13th, 2007 02:30 PM
hlpe with foreach(); haryohnesa PHP Databases 1 August 3rd, 2006 12:46 PM
"foreach" error BradBrening Pro PHP 2 January 13th, 2005 05:33 PM
Need help with foreach loop Arsi C# 3 September 7th, 2004 09:41 PM
for loops from within foreach richard.york Pro PHP 5 October 2nd, 2003 01:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.