Want to convert a list<any type> to a list of type Generic?

Asked

Viewed 137 times

-2

I want a list of a certain type to become a list of a single type : examples

List<usuarios> se transformar em uma List<T> 

BS : I don’t know if that’s possible Or an Apple List becomes a Lista<T> the reason is that I have a method that only accepts listas<T> I wanted him to accept anything...

  • Gabriel, welcome to Stackoverflow. I recommend reading on tour to understand a little more how things work around here.

  • 1

    Could it be [Dit] and post an example of a piece of code that has tried to apply this idea? (that part of the method that commented, and the code that should call this method). It would be good if you explained what you wanted to happen, and what actually happened. Ideally, a [mcve].

1 answer

1

The very one List<T> is already a Generic, just you pass the Type as List<string> for example and will have a generic list. If you need a list that accepts any type you can use Arraylist or List itself by passing Object in type (List<Object>).

  • 2

    Hello, Stan; It would be nice if you could edit your response by adding an example of code to illustrate it better. (Demonstrating that the <T> is indeed any type, would make it easier for the author to view)

  • Vlw Bacco for the tip

Browser other questions tagged

You are not signed in. Login or sign up in order to post.