473,394 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Which is best?

1
Hello folks, the two code blocks below do the same thing, which is set a few form field values. Clearly the first method is the most elegant but my question is which is best in terms of lightest server loading and efficiency? Is looping through collections more time and memory consuming then simply dropping through a switch-block?

METHOD 1:

foreach (Control c in this.pnlRows.Controls)
{
if (c is RadioButtonList && ((RadioButtonList)c).ID.ToString().Contains(RowsCt rlID))
{
((RadioButtonList)c).Items.FindByValue(RowsRequire d).Selected = true;
}
if (c is TextBox && ((TextBox)c).ID.Contains(RowsCtrlID))
{
((TextBox)c).Text = RowsItemText;
}
}

================================================== ========================

METHOD 2:


switch (RowsCtrlID)
{
case "fRowText1":
fRowText1.Text = RowsItemText;
fRowText1Required.Items.FindByValue(RowsRequired). Selected = true;
break;

case "fRowText2":
fRowText2.Text = RowsItemText;
fRowText2Required.Items.FindByValue(RowsRequired). Selected = true;
break;

case "fRowText3":
fRowText3.Text = RowsItemText;
fRowText3Required.Items.FindByValue(RowsRequired). Selected = true;
break;

case "fRowText4":
fRowText4.Text = RowsItemText;
fRowText4Required.Items.FindByValue(RowsRequired). Selected = true;
break;

case "fRowText5":
fRowText5.Text = RowsItemText;
fRowText5Required.Items.FindByValue(RowsRequired). Selected = true;
break;

case "fRowText6":
fRowText6.Text = RowsItemText;
fRowText6Required.Items.FindByValue(RowsRequired). Selected = true;
break;

case "fRowText7":
fRowText7.Text = RowsItemText;
fRowText7Required.Items.FindByValue(RowsRequired). Selected = true;
break;

case "fRowText8":
fRowText8.Text = RowsItemText;
fRowText8Required.Items.FindByValue(RowsRequired). Selected = true;
break;

case "fRowText9":
fRowText9.Text = RowsItemText;
fRowText9Required.Items.FindByValue(RowsRequired). Selected = true;
break;

case "fRowText_10":
fRowText_10.Text = RowsItemText;
fRowText_10Required.Items.FindByValue(RowsRequired ).Selected = true;
break;

case "fRowText_11":
fRowText_11.Text = RowsItemText;
fRowText_11Required.Items.FindByValue(RowsRequired ).Selected = true;
break;

case "fRowText_12":
fRowText_12.Text = RowsItemText;
fRowText_12Required.Items.FindByValue(RowsRequired ).Selected = true;
break;

case "fRowText_13":
fRowText_13.Text = RowsItemText;
fRowText_13Required.Items.FindByValue(RowsRequired ).Selected = true;
break;

case "fRowText_14":
fRowText_14.Text = RowsItemText;
fRowText_14Required.Items.FindByValue(RowsRequired ).Selected = true;
break;

case "fRowText_15":
fRowText_15.Text = RowsItemText;
fRowText_15Required.Items.FindByValue(RowsRequired ).Selected = true;
break;

case "fRowText_16":
fRowText_16.Text = RowsItemText;
fRowText_16Required.Items.FindByValue(RowsRequired ).Selected = true;
break;

default:
break;
}
Jul 12 '07 #1
1 1645
Plater
7,872 Expert 4TB
I would say the first one is better overall. The complier can probably optimize its own functions much better.
PLUS: You don't really use the value of RowsCtrlID in the switch statement very effectively. A lot of extra code is compiled for it.
Jul 12 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: CY FOK | last post by:
Hi I am planning to open a software company to develop client-server apps and web applications for my client. Now, i am in a difficult situation to determine what is the best platform i should use...
1
by: JJ | last post by:
Hi, I was going to buy a server with Raid 1 as I thought that it meant that if one of the two mirrored drives fail, you simply take it out and put a new one in. At which point presumably the...
3
by: Balaji Kannan | last post by:
Hi, In dot net during component development i have used some member variables in the class file. Inside the class i have used the member declaration and the instant handling in the following...
17
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
34
by: Jeff | last post by:
For years I have been using VBA extensively for updating data to tables after processing. By this I mean if I had to do some intensive processing that resulted in data in temp tables, I would have...
24
by: invitro81 | last post by:
Hello I've recently learnt python and I do love it! I congratulate all those geeks who produce this nice language; well, because I could be called a nearby newbee I've decided to improve my...
3
by: ram_palavalasa | last post by:
Hi all, Whichone is the best among the following while proessing the data? ODBC,DAO,ADO,OLEDB...please justify urself why ? also let me know how to loas dll component to the workspace in...
16
by: John Salerno | last post by:
My initial feeling is that concatenation might take longer than substitution, but that it is also easier to read: def p(self, paragraph): self.source += '<p>' + paragraph + '</p>\n\n' vs. ...
5
nehashri
by: nehashri | last post by:
hi can ne1 plz guide me as to which interface is best for posgresql. i have started using posgrsql recently. i am making a biological database which has a frontend allowing the user to select...
103
by: Tom | last post by:
How do we get out of the browser infinite loop quicksand when we navigate to web pages designed to lock us in and force us to hit the "pay me" button (whatever they want to force you to do)? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.