c# generics

hi, I have 5 functions which is called with 5 different parameters, but i found out that i can reduce these 5 functions to 2 via utilizing generics , the reason i can not reduce to one is the parameters sent to 1 of the functions is List<T>
the other one is T ,  signature is as below;

is there a way for me to reduce this into 1 function only utilizing generics again?

myfunction1(List<T> request)
myfunction2(T request)
nicedoneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
It would really depend on the implementation of each function, I think, but perhaps you can change the signature of the first function to take in an IEnumerable rather than a List:

myfunction1(IEnumerable<T> request)

Then, whenever you have a single element, you could simply construct an anonymous enumerable:

T request = something;
var anonEnumerable = new[] { request };
myfunction1(anonEnumerable);

But again, this depends on the implementation of each function.
0
nicedoneAuthor Commented:
basically this is the implementation of the functions same logic

   protected void LogRequest<T>(List<T> updateRequests)
        {
            foreach (var request in updateRequests)
            {
                string jsonRequest = JsonConvert.SerializeObject(request);
                Log.DebugFormat("RequestBody : {0}", string.Join(",", jsonRequest));
            }
        }

Open in new window

0
käµfm³d 👽Commented:
That should be fine then. I was only concerned with you accessing the items by index--since you were using a List. Because you are only doing a foreach over the elements, there should be no reason why you cannot use IEnumerable instead. This also opens your code up to being used for collections outside of List, collections like Queue, Dictionary, Stack, etc.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nicedoneAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.