I have the following:
public class Sort
{
public static void ShuffleGenericList<T>(IList<T> list)
{
//generate a Random instance
Random rnd = new Random();
//get the count of items in the list
int i = list.Count();
...
...
}
}
Should my class also be static or is it okay with just the method being static?
Marking classes as
staticis purely optional (if they don’t contain extension methods).In other words, a static class‘ members must also be static, but generally static members can be declared in any class:
From the common sense, you should (but don’t have to) mark class as
staticwhen:For example,
new Sort()might or might not make any sense in your code, depending on what’s in the class, etc. From the sample you provided, I think marking it static is the way to go.Note, though, that you have to mark class as
staticwhen it contains extension methods you intend to use in other parts of your code. Classes that contain extension methods must be static.