vb.net Dictionary(Of String,Object)enum.getname()(vb.net Dictionary(Of String, Object) enum.getname(

编程入门 行业动态 更新时间:2024-10-27 16:33:46
vb.net Dictionary(Of String,Object)enum.getname()(vb.net Dictionary(Of String, Object) enum.getname())

我正在做一个VB.Net WinForm应用程序。 这是C#的迁移。

在C#中,我有一个像这样定义的变量。

 private static Dictionary<string, ExportFormatType> dicExtensiones =
            new Dictionary<string, ExportFormatType> {
                        {".pdf", ExportFormatType.PortableDocFormat},
                        {".doc", ExportFormatType.WordForWindows},
                        {".xls", ExportFormatType.Excel},
                        {".rtf", ExportFormatType.RichText},
                        {".html", ExportFormatType.HTML40},
                        {".txt", ExportFormatType.Text}
                   };
 

我迁移到了这个..

   Private Shared dicExtensiones = New Dictionary(Of String, ExportFormatType) From
                            {{".pdf", ExportFormatType.PortableDocFormat},
                             {".doc", ExportFormatType.WordForWindows},
                             {".xls", ExportFormatType.Excel},
                             {".rtf", ExportFormatType.RichText},
                             {".html", ExportFormatType.HTML40},
                             {".txt", ExportFormatType.Text}}
 

现在我需要遍历所有ítems并获得每个值...

在C#中是这样的。

 List<String> lista = new List<string>();

            foreach (var item in dicExtensiones)
            {
                lista.Add(Enum.GetName(typeof(ExportFormatType), item.Value));
                lista.Add("*" + item.Key);
            }
 

我遇到的问题是我确实知道如何迁移

Enum.GetName(typeof(ExportFormatType), item.Value);

到VB.Net,因为VB.Net中不存在Enum.GetName

我该怎么做?

I am doing an VB.Net WinForm Application. It is a migration of C#.

In C# I have a variable defined like this.

 private static Dictionary<string, ExportFormatType> dicExtensiones =
            new Dictionary<string, ExportFormatType> {
                        {".pdf", ExportFormatType.PortableDocFormat},
                        {".doc", ExportFormatType.WordForWindows},
                        {".xls", ExportFormatType.Excel},
                        {".rtf", ExportFormatType.RichText},
                        {".html", ExportFormatType.HTML40},
                        {".txt", ExportFormatType.Text}
                   };
 

And i migrated to this..

   Private Shared dicExtensiones = New Dictionary(Of String, ExportFormatType) From
                            {{".pdf", ExportFormatType.PortableDocFormat},
                             {".doc", ExportFormatType.WordForWindows},
                             {".xls", ExportFormatType.Excel},
                             {".rtf", ExportFormatType.RichText},
                             {".html", ExportFormatType.HTML40},
                             {".txt", ExportFormatType.Text}}
 

Now I need to Loop through all ítems and get each value...

In C# is like this.

 List<String> lista = new List<string>();

            foreach (var item in dicExtensiones)
            {
                lista.Add(Enum.GetName(typeof(ExportFormatType), item.Value));
                lista.Add("*" + item.Key);
            }
 

The problem i have is that I do know how to migrate

Enum.GetName(typeof(ExportFormatType), item.Value);

to VB.Net, because Enum.GetName does not exists in VB.Net

How can I do it?

最满意答案

它可以像下面的VB一样

Dim lista As List(Of [String]) = New List(Of String)() For Each item As var In dicExtensiones lista.Add([Enum].GetName(GetType(ExportFormatType), item.Value)) lista.Add("*" + item.Key) Next

it can be like below in VB

Dim lista As List(Of [String]) = New List(Of String)() For Each item As var In dicExtensiones lista.Add([Enum].GetName(GetType(ExportFormatType), item.Value)) lista.Add("*" + item.Key) Next

更多推荐

本文发布于:2023-07-29 05:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1312612.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Dictionary   net   vb   String   getname

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!