I'm working on a personal project and decided to try to save some methods I'll continue to use for other projects to their own namespace, to be imported into files as needed.
namespace MyUtils
{
namespace Cards
{
public class Cards
{
public void Shuffle(List<int> deck)
{
//shuffles the given deck
}
}
}
}
My goal is to set it up so that I don't have to import all of my methods into a file or program every time, so with the nested namespace I'm able to use using MyUtils.Cards
to just import the Cards methods without needing to bring in every other method that may not be needed for a given project.
Now in my Program file, the only way I've gotten this to work is to create an object Cards c = new Cards()
and then call c.Shuffle(list);
. Is there a way I can set this up where I can call the Shuffle method without having to create a Cards object? Ideally, I'd like to be able to just create a List and then call Shuffle(list)
, but I can't figure out how to do so.
My first thought was to move the Shuffle method out of the Cards class and into the Cards namespace block, but it seems that methods can't go directly into namespaces. If this can't be done with namespaces and using
, is there another way I could create a set of methods and store them in a way where they can be reused in multiple programs?