开发者

How to get a list of all SQl Data Types on c#?

Is there any way to get some list of all Sql Data Types on c#?

I know that we have a Enum called SQlDbType which contains all Sql Data Types, but can we convert an Enum to an array of strings?

I only want to get some list with all Sql Data Types, instead开发者_C百科 of writing them one by one and adding them into my array of strings.


Enum to an array of strings is pretty easy:

var names = Array.ConvertAll((SqlDbType[]) Enum.GetValues(typeof(SqlDbType)),
                             type => type.ToString());

or using LINQ:

var names = Enum.GetValues(typeof(SqlDbType))
                .Cast<SqlDbType>()
                .Select(x => x.ToString())
                .ToArray();

Or more pleasantly using my Unconstrained Melody library, either as an array or (more efficiently) an immutable list:

string[] names = Enums.GetNamesArray<SqlDbType>();

IList<string> namesList = Enums.GetNames<SqlDbType>();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜