我想從另一個cs文件調用方法。我創建了該方法存在於類的新實例,但得到這個錯誤:類型''沒有構造函數定義C#
The type 'SteamKit2.SteamFriends' has no constructors defined
誰能幫助我瞭解爲什麼發生這種情況?
,其中我試圖從被如下
using System;
using SteamKit2;
using SteamTrade;
using System.Collections.Generic;
using SteamBot;
namespace SteamBot
{
public class HarvesterHandler : UserHandler
{
public int FriendCount = 0;
public int FriendToTrade = 0;
SteamFriends me = new SteamFriends();
public override void OnLoginCompleted()
{
FriendCount = me.GetFriendCount();
if (FriendToTrade < FriendCount)
{
Bot.SteamTrade.Trade(me.GetFriendByIndex(FriendToTrade));
Log.Info("Sending Trade Request to Friend " + FriendToTrade + " of " + FriendCount);
return;
}
while (true)
{
Log.Warn("Finished trading");
}
}
}
}
的稱爲類如下(在一個單獨的CS文件)
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SteamKit2.Internal;
namespace SteamKit2
{
public sealed partial class SteamFriends : ClientMsgHandler
{
object listLock = new object();
List<SteamID> friendList;
List<SteamID> clanList;
AccountCache cache;
internal SteamFriends()
{
friendList = new List<SteamID>();
clanList = new List<SteamID>();
cache = new AccountCache();
}
public int GetFriendCount()
{
lock (listLock)
{
return friendList.Count;
}
}
public SteamID GetFriendByIndex(int index)
{
lock (listLock)
{
if (index < 0 || index >= friendList.Count)
return 0;
return friendList[ index ];
}
}
}
}
儘量使構造'public',而不是'internal' – Nolonar