I have:
public static class DataManager
{
private static Dictionary<string, DataTable> dataTables;
// extension method
public static DataTable GetTable ( this string TableName )
{
return dataTables[ TableName ];
}
}
I didn't want to expose the Dictionary collection, and this is the way I thought to accomplish this task. In my calling method:
DataTable GetTable (string TableName)
{
return TableName.GetTable();
}
Is there another way I should, or could do this? Or is this acceptable?
I don't think that this is a good idea because, your method does not operate on a string
(what the extension method would state), it operates on DataManager
. So just use a static method in this case.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.