|
-
Jun 19th, 2007, 08:31 PM
#1
Thread Starter
Fanatic Member
[2.0] using with w/ c#
how can to avoid duplication of control like comboBox1?
comboBox1.Items.Add("Item 1");
comboBox1.Items.Add("Item 2");
comboBox1.Items.Add("Item 3");
just like in VB, it should be;
with comboBox1
.Items.Add("Item 1");
.Items.Add("Item 2");
.Items.Add("Item 3");
end with
-
Jun 19th, 2007, 08:48 PM
#2
Re: [2.0] using with w/ c#
Assign comboBox1.Items to a local variable and then refer to it each time C# has no direct equivalent to With.
-
Jun 19th, 2007, 11:30 PM
#3
Thread Starter
Fanatic Member
Re: [2.0] using with w/ c#
Assign comboBox1.Items to a local variable and then refer to it each time C# has no direct equivalent to With.
how? kindly help me?
-
Jun 20th, 2007, 12:49 AM
#4
Fanatic Member
Re: [2.0] using with w/ c#
Simply as JM said, there's no equivalent with With in C#. You more or less do it like this
foreach (string s in new string[] {"a", "b", "c"}) { combo.Items.Add(s); }
-
Jun 20th, 2007, 02:02 AM
#5
Re: [2.0] using with w/ c#
 Originally Posted by arshesander
Assign comboBox1.Items to a local variable and then refer to it each time C# has no direct equivalent to With.
how? kindly help me?
Think first, ask questions later. You already know how to declare a local variable and assign something to it.
-
Jun 20th, 2007, 09:38 PM
#6
Hyperactive Member
Re: [2.0] using with w/ c#
Let's give him a break, I think he really doesn't understand.
Here it is:
Code:
ObjectCollection o = comboBox1.Items;
o.Add("Item 1");
o.Add("Item 2");
o.Add("Item 3");
____________________________________________
Please rate my messages. Thank you!
____________________________________________
Bram Vandenbon
http://www.bramvandenbon.com
-
Jun 20th, 2007, 10:13 PM
#7
Re: [2.0] using with w/ c#
 Originally Posted by BramVandenbon
Let's give him a break, I think he really doesn't understand.
I disagree. I think people have a tendency to assume they don't understand without considering the problem properly. I very much doubt that arshesander has made it this far without having had to declare a local variable and assign a value to it. You may prefer to hand over a fish but I prefer to push people to learn to fish for themselves, especially when they already know how but don't realise it. In the long run that is more beneficial to someone's learning.
-
Jun 21st, 2007, 09:55 AM
#8
Re: [2.0] using with w/ c#
I'll have to agree, this was way too simple to not understand.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|