2

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

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;
        }
    }
}

老实说,我是一个 C# 新手。但我不明白为什么这是不可能的。是因为我将 o 的引用传递给 this.Variable 吗?

这样做的目标应该是我能够重用 NaServer 对象。

4

2 回答 2

2
private NaServer NetappServer {get; set;}

public NaServer NetappServer()

同名,换一个。

于 2012-09-22T22:51:24.797 回答
0

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

class MyClass 
{
   private SomeObject _variable;

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

Visual Studio 的 C# 编辑器和 C# 编译器可以很好地提示您可能出现的问题。考虑到他们!

于 2012-09-22T22:52:34.507 回答