Click here to Skip to main content
16,014,671 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In order to return a List, making four different functions call is better or only single Function call is better

i.e.
I want a List<> as return type from a function.
e.g. List<t> GetData()

I am using four different overloading to get the List<t> as
GetData(int a) //here need only x from T as return
GetData(int a, int b) //here need only x and y from T as return
GetData(int a, string c) //here need only y from T as return
GetData(string a) //here need only z from T as return


Also I can do like,

GetData(Type T)


Which is better to use? Sending particular variable as parameter or Type as a parameter? Why?
Posted
Comments
Sreekanth Mothukuru 31-Aug-15 6:48am    
I feel writing a single generic method GetData(T t) to return List is the best way. What do you think?

1 solution

It just depends on your purpose, on how integral your set of parameters are. It also depends on how typical would be the reuse of the instance of this input data type (I mean, the cases when you create one instance and use it in several calls to GetData.

Only your code sample GetData(Type T) doesn't look relevant to your question, because the name "Type" suggests System.Type which should not be used like that. Instead of "Type", it should be your class or structure name, say "MyData". And with struct, it could be GetData(ref MyData data) (do I even have to explain why?)…

—SA
 
Share this answer
 
v4
Comments
durgeshtupkar10 10-Sep-15 3:49am    
Thanks,

Another query is, in case of returning multiple fields from different tables in Linq query, is it good to use return type as object or should be used a new class containing those selected fields of Linq query?
Sergey Alexandrovich Kryukov 10-Sep-15 4:31am    
What "another query"? You still did not accept this answer...
—SA
durgeshtupkar10 21-Jun-17 4:00am    
accepted

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