【问题标题】:Problems converting VB.NET to C#将 VB.NET 转换为 C# 的问题
【发布时间】:2011-10-19 21:52:16
【问题描述】:

我正在尝试将一些 vb.net 转换为 C#,但我不断收到错误。目前,我收到以下错误:

The name 'Strings' does not exist in the current context

问题行是:

strUser = Strings.LCase(Strings.Trim(strUserInitials[strUserInitials.GetUpperBound(0)])).ToString();

有人知道为什么会这样吗?

我设置了以下命名空间:

using System;
using System.Web;
using System.Web.Services;
using System.Web.Script;
using System.Web.Script.Services;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

我正在开发一个网络服务(asmx 文件)。

【问题讨论】:

    标签: c# .net .net-3.5 asmx vb.net-to-c#


    【解决方案1】:

    Strings 实用程序类位于 Microsoft.VisualBasic 命名空间中。

    您可以添加对该库的引用并在您的 C# 代码中使用它,或者重写调用:

    strUser = strUserInitials[strUserInitials.GetUpperBound(0)].ToString().Trim().ToLower();
    

    【讨论】:

      【解决方案2】:

      在 c# 中,System 命名空间中没有 Strings 类。并在string 中将LCase 更改为ToLower,所以:

      strUser = string.ToLower(string.Trim(strUserInitials[strUserInitials.GetUpperBound(0)]));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多