Hy,
I have some methods which are identical as functionality but dependent on the parameter received from the method.For example:

 public long GetElementsFromList(long el,List<long> lst)
        {
            Random rndElement = new Random();        
            int random = rndElement.Next(0, this.lst.Count - 1);
            if (random >= this.lst.IndexOf(el)) random += 1;
            return this.lst[random];
        }
       public string GetElements2FromList(string el,List<string> lst)
        {
            Random rndElement = new Random();  
            int random = rndElement.Next(0,this.sucursale.Count-1);
            if (random >= this.lst.IndexOf(el)) random += 1;
            return this.lst[random];
        }

I want to have a generic method which is not dependent on the return value and also on the type of parameter.
I'm thinking about generics but i cannot handle myself.

Some advice?Thank you

have you tried using Val or Value ? it should store the value you store in it in the most appropriate format type.

Can't you make an extension method for the List class? Here are some samples.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.