【问题标题】:Need to convert this code to VB [closed]需要将此代码转换为VB [关闭]
【发布时间】:2012-08-12 20:00:52
【问题描述】:

我根本不熟悉 C#.NET。我需要将其转换为 VB。谁能帮我一把?

public IEnumerable<CodecInfo> AudioCodecs
        {
            get { return softPhone.Codecs.Where(c => c.CodecType == CodecMediaType.Audio); }
        }

谢谢

【问题讨论】:

  • 这只是返回为 CodecMediaType.Audio 过滤的编解码器集合...
  • 在语言之间翻译代码对 SO 来说并不是一个合适的问题...
  • 有在线翻译你可以使用here是其中之一。
  • 有很多在线工具对于像这样的简单情况非常有用。例如converter.telerik.com

标签: c# vb.net ienumerable c#-to-vb.net


【解决方案1】:
Public ReadOnly Property AudioCodecs As IEnumerable(Of CodecInfo)
    Get
        Return From c In softPhone.Codecs
               Where c.CodecType = CodecMediaType.Audio
    End Get
End Property

查询语法比VB.NET中的方法语法可读性强得多

【讨论】:

  • 查询语法在 VB.NET 中更具可读性 - 没错,它甚至比 C# 更强大
  • 这比 C# 中的相同查询更具可读性吗? from c in softPhone.Codecs where c.CodecType == CodecMediaType.Audio,对吧?对我来说看起来很容易阅读(除了在评论中)。
  • 我看不出它比 C# 版本更具可读性。 LINQ 语法在两种语言中相当一致。这里唯一的关键区别是 C# 版本压缩了空间以将属性访问器和代码放在一行中,而 VB.Net 强制您使用多行,但这不是查询语法本身。
  • 也许这不是最好的例子,所以看看这个:stackoverflow.com/a/9039282/284240
  • 你们都误解了我的笔记,所以我编辑了我的答案以澄清它(希望如此)。
【解决方案2】:
Public ReadOnly Property AudioCodecs() As IEnumerable(Of CodecInfo)
    Get
        Return softPhone.Codecs.Where(Function(c) c.CodecType = CodecMediaType.Audio)
    End Get
End Property

将来您可以使用 C#-VB.NET 转换器:

http://www.developerfusion.com/tools/convert/csharp-to-vb/

【讨论】:

    【解决方案3】:
    Public ReadOnly Property AudioCodecs() As IEnumerable(Of CodecInfo)
        Get
            Return softPhone.Codecs.Where(Function(c) c.CodecType = CodecMediaType.Audio)
        End Get
    End Property
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-21
      • 1970-01-01
      • 2012-11-21
      • 1970-01-01
      • 2022-01-17
      • 1970-01-01
      相关资源
      最近更新 更多