this example uses generic extention method to convert a list of any type to a string comma sperated list
///
/// Contains List Extention Methods
///
public static class ListExtentions
{
///
/// Converts the current list items to a comma seperated string
///
///
/// My list.
///
public static string ToCommaSeperated
{
string ret = string.Empty;
for (int i = 0; i < myList.Count; i++)
{
if (myList[i] != null &&
!string.IsNullOrEmpty(myList[i].ToString()))
{
if (i == 0)
ret = myList[i].ToString();
else
ret += "," + myList[i].ToString();
}
}
return ret;
}
}
}
to use the function you can do the following
List
lstUser.ToCommaSeperated();
as long as you did a proper override of the ToString() virtual method you should get a proper list of comma seperated User names for example
public class CustomUserObject
{
.
.
.
public override string ToString()
{
return firstName+" "+lastName;
}
Enjoy ;)
}

0 comments:
Post a Comment