troubleshooting Question

Using generics in C# ASP .Net 2.0

Avatar of hamidovt
hamidovt asked on
.NET ProgrammingEditors IDEs
6 Comments2 Solutions2165 ViewsLast Modified:
I am using trying to use List of <T> generics in C# ASP.NET 2.0. In my code I have a a method that returns a list of objects with the following definition. Something like

public static List<Location> GetAll()
   List<Location> locations = new List<Location>();
   return locations;

This part of using generics is OK. My problem is that I would like to pass a List of <T> to another method. The code would look something like this

protected string Locations(List<Location> locations)
  string locationsString = string.Empty;
  foreach(Location lc in locations)
    locationsString += lc.Name + " ";
  return locationsString;

However I eceive  a compilation error saying that type or namespace name 'List' could not be found.
My questions are:
- is it possible to path a List<T> ?
- what is the right syntax to do that in C# ?

Thanks in advance!

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 6 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 2 Answers and 6 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