Click here to Skip to main content
15,911,531 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to hard code for states and cities..

i am having 50 functions as i am having 50 states, from which i am calling a function on combobox1_selectedindexchanged event.
.
for that i have create a switch case with 50 cases. where combobox1's selected index is passed as a case no.
now 10 functions are to be added, i think switch case is not being convenient for that,
.
so i have a idea, is it possible?

C#
functionName+combobox.selectedindex+();


so that my 60 cases will reduced to only one function ??
.
or there is any other option..

.
Posted
Updated 28-Sep-14 21:58pm
v2
Comments
Jameel VM 29-Sep-14 4:01am    
can you please post the function you have tried?
Gihan Liyanage 29-Sep-14 4:02am    
I cant correctly understand what is the problem. But according to your details , I think you may want to find a one Item from list of strings. Is it ?
Richard MacCutchan 29-Sep-14 4:16am    
No it is not possible. And using a switch statement with 50 cases in this way is totally the wrong way to go about things.
jaket-cp 29-Sep-14 4:29am    
You may want to look at.
Passing Parameters (C# Programming Guide)
http://msdn.microsoft.com/en-us/library/0f66670z.aspx
So I believe in your example, you could call the function like this
functionName(combobox.selectedindex);
That is if I understand what you are trying to do.
[no name] 29-Sep-14 5:49am    
you can achive this by Enums

1 solution

You might use an array of delegates, see for instance, here: "Array of Function Pointers?"[^].
 
Share this answer
 
Comments
BillWoodruff 29-Sep-14 6:40am    
Let's see if the OP can understand the content in this link.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900