저는 C #을 처음 접했고 현재 콘텐츠에 내 클래스 개체가 "존재하지 않는"이유를 알 수 없습니다. 개체를 재구성하고 호출하는 여러 방법을 시도했지만 여전히 "현재 컨텍스트에 'ExcuteObject'라는 이름이 없습니다.
namespace DBTest4
{
class Program
{
class MacroInfo
{
public int MsgSN { get; set; }
public int FormID { get; set; }
public int Leg { get; set; }
public int Stop { get; set; }
public MacroInfo(DataRow row)
{
this.MsgSN = Convert.ToInt32(row["MsgSN"]);
this.FormID = Convert.ToInt32(row["FormID"]);
this.Leg = Convert.ToInt32(row["Leg"]);
this.Stop = Convert.ToInt32(row["Stop"]);
}
public DataTable Ch(string commandsqlstring, bool isStoredProcedure = false)
{
DataTable dataTable = new DataTable();
......
return dataTable;
}
public IEnumerable<T> ExcuteObject<T>(string storedProcedureorCommandText, bool isStoredProcedure = true)
{
List<T> items = new List<T>();
.....
return items;
}
}
static void Main(string[] args)
{
string commandsqlstring = "Select top 10 MsgSN,FormID,Leg,Stop from tmail.MacroSendReceiveHistory order by ID desc";
bool SP = false;
List<MacroInfo> macroInfos = new List<MacroInfo>();
macroInfos = ExcuteObject<MacroInfo>(commandsqlstring, SP).ToList();
Console.ReadLine();
}
}
}
Excute Object가 보이지 않는 이유는 무엇입니까?
ExcuteObject
클래스의 메소드가 아니라 클래스의 MacroInfo
메소드입니다 Program
. ExcuteObject
메서드가 정적이고 "Program"클래스의 메서드 이면 현재 구현이 작동했을 것 입니다.
이 문제를 해결하려면. 다음 중 하나를 수행 할 수 있습니다.
ExcuteObject
메서드를 Program
클래스로 이동 하고 정적으로 만듭니다.ExcuteObject
의 MacroInfo
클래스 만 만들 ExcuteObject
방법 정적과에 전화 Program
로 클래스MacroInfo.ExcuteObject(...)
MacroInfo
클래스 의 인스턴스를 만들고 클래스 의 인스턴스 에서 메서드를 호출합니다 MacroInfo
.이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다