class A
{
public static List<String> a = new List<string>();
public static List<String> test()
{
A.a.Add("20");
A.a.Add("30");
A.a.Add("40");
return a.Sort();
}
}
Throws up a compile error :
Cannot implicitly convert void to System.Collections.Generic.List.
But, If I write a method to get the List<String> value (since it is the static member variable) everything should work fine. But, I am unaware why despite my method returning a List<String> value, why does the compiler throw this error ?
The
List<T>.Sort()method doesn’t return aList<T>. It’s avoidmethod – it sorts the list in place. You need:Basically a method with a
voidreturn type can only be used as a standalone statement. You can’t use it as an expression to return, or as a method argument etc.