带有私有变量的C#模糊性

带有私有变量的C#模糊性,c#,C#,让我给你一个简单的例子来说明我的问题。我似乎无法理解错误: using System; using System.Collections.Generic; using System.Linq; using System.Text; using NetApp.Manage; namespace Toaster.Library { class NetappConnection { private string Hostname {get; set;}

让我给你一个简单的例子来说明我的问题。我似乎无法理解错误:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using NetApp.Manage;

namespace Toaster.Library
{
    class NetappConnection
    {
        private string Hostname     {get; set;}
        private int ApiMajor        {get; set;}
        private int ApiMinor        {get; set;}
        private string Username     {get; set;}
        private string Password     {get; set;}

        private NaServer NetappServer {get; set;}

        public void NetappConnection(string Hostname, int ApiMajor, int ApiMinor,     string Username, string Password)
        {
            this.Hostname = Hostname;
            this.ApiMajor = ApiMajor;
            this.ApiMinor = ApiMinor;
            this.Username = Username;
            this.Password = Password;

            this.ConnectToNetapp();
        }

        private void ConnectToNetapp()
        {
            NaServer s = new NaServer(this.Hostname, this.ApiMajor, this.ApiMinor);
            s.ServerType = NaServer.SERVER_TYPE.FILER;
            s.TransportType = NaServer.TRANSPORT_TYPE.HTTP;
            s.Port = 80;
            s.Style = NaServer.AUTH_STYLE.LOGIN_PASSWORD;
            s.SetAdminUser(this.Username, this.Password);

            this.NetappServer = s; <<-- Error: Ambiguity between 'Toaster.Library.NetappConnection.NetappServer' and 'Toaster.Library.NetappConnection.NetappServer()'
        }

        public NaServer NetappServer()
        {
            return this.NetappServer;
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用NetApp.Manage;
名称空间Toaster.Library
{
类NetApp连接
{
私有字符串主机名{get;set;}
私有int{get;set;}
私有int{get;set;}
私有字符串用户名{get;set;}
私有字符串密码{get;set;}
专用NaServer NetappServer{get;set;}
public void NetappConnection(字符串主机名、int-ApiMajor、int-ApiMajor、字符串用户名、字符串密码)
{
this.Hostname=Hostname;
this.ApiMajor=ApiMajor;
this.apimoner=apimoner;
this.Username=用户名;
this.Password=密码;
this.ConnectToNetapp();
}
私有void ConnectToNetapp()
{
NaServer s=新的NaServer(this.Hostname、this.ApiMajor、this.ApiMinor);
s、 ServerType=NaServer.SERVER\u TYPE.FILER;
s、 TransportType=NaServer.TRANSPORT\u TYPE.HTTP;
s、 端口=80;
s、 Style=NaServer.AUTH\u Style.LOGIN\u密码;
s、 SetAdminUser(this.Username,this.Password);
this.NetappServer=s;
及


如果名称相同,请更改一个。

属性有getter和/或setter
get;set;
。变量没有。关键字
class
为小写(根据CodesInChaos)。字段(或类成员变量,如果您愿意)通常使用前导下划线和_camel大小写,即第一个字母为小写,后续部分以大写字母开头

class MyClass 
{
   private SomeObject _variable;

   public void SomeMethode()
   {
      _variable = new SomeObject();
   }
}


Visual Studio的C#编辑器和C#编译器为您提供了很好的错误提示。请将它们考虑在内!

这应该会给出错误的唯一原因是因为您使用大写字母编写了
Class
。这里还有一些错误。如前所述,假设您键入的类声明错误,那么这段代码。你能以完整的形式发布实际错误吗?以及真实的类?首先,这不是一个变量,而是一个属性。omg应该看到:(thanks@Norynda另外:从
NetappConnection
thx的构造函数中删除
void
,这样做了,无意中发现了这一点……您所说的话是有效的(虽然圣战开始于下划线),但我不确定这是否真的适用于这个问题…?OP同时更改了他的代码示例。
public NaServer NetappServer()
class MyClass 
{
   private SomeObject _variable;

   public void SomeMethode()
   {
      _variable = new SomeObject();
   }
}