troubleshooting Question

Help with genericss

Avatar of vbhargav80
vbhargav80 asked on
2 Comments1 Solution251 ViewsLast Modified:
Dear Experts,

I'm trying to create a generic method that should return a list based on whatever type the caller is interested in. I am new to generics and am completely stuck.

Here is my code. Can you please point out the mistake?
/// <summary>
        /// Values that have been added to the secondary list to be blocked/excluded
        /// </summary>
        public IList<T> GetSecondaryListValues<T>()
            IList<T> selectedValues = new List<T>();
            foreach (ListItem item in lstSecondary.Items)
                selectedValues.Add(Convert.ChangeType(item.Value, typeof(T)));
            return selectedValues;
Jaime Olivares
Software Architect
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros