我正在創建一個項目,該項目將使用streamreader
讀取數據文件,並在Windows窗體中顯示數據。關於c#類與圖像的混淆
但是,該數據文件的其中一個屬性是圖像。由於我從來沒有真正使用過圖像,在c#中,我有點困惑。
做我創建了一個名爲team
類和管理,建立Image
using System.Drawing;
的聲明,但是我不知道我是多麼應該建立在類的構造函數與圖像的一些現有的研究或獲取/設置方法。
我設法在網上找到的一般用途和Image
類的提示沒有把它放在你自己創建的類中。這是我到目前爲止。
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Drawing;
namespace teams_2
{
class Team
{
string teamName;
string teamLeague;
string teamManager;
string teamNickname;
string teamStadium;
int leaguePosistion;
int leaguePoints;
int gamesPlayed;
int goalDifference;
int playerNumber;
Image teamLogo; //the problem
//constructor(image?)
//team order = teamName teamLeague teamManager teamNickname teamStadium leaguePosistions leaguePoints gamesPlayed goalDifference playerNumber teamLogo
public Team(string inTeamName, string inTeamLeague, string inTeamManager, string inTeamNickname,
string inTeamStadium, int inLeaguePosistion, int inLeaguePoints, int inGamesPlayed,
int inGoalDifference, int inPlayerNumber)
{//
teamName = inTeamName;
teamLeague = inTeamLeague;
teamManager = inTeamManager;
teamNickname = inTeamNickname;
teamStadium = inTeamStadium;
leaguePosistion = inLeaguePosistion;
leaguePoints = inLeaguePoints;
gamesPlayed = inGamesPlayed;
goalDifference = inGoalDifference;
playerNumber = inPlayerNumber;
}//end constructor
//begin getters
public string getTeamName()
{
return teamName;
}
public string getTeamLeague()
{
return teamLeague;
}
public string getTeamManager()
{
return teamManager;
}
public string getTeamNickname()
{
return teamNickname;
}
public string getTeamStadium()
{
return teamStadium;
}
public int getLeaguePosistion()
{
return leaguePosistion;
}
public int getLeaguePoints()
{
return leaguePoints;
}
public int getGamesPlayed()
{
return gamesPlayed;
}
public int getGoalDifference()
{
return goalDifference;
}
public int getPlayerNumber()
{
return playerNumber;
}
//end getters
//begin setters
public void setTeamName(string inTeamName)
{
teamName = inTeamName;
}
public void setTeamLeague(string inTeamLeague)
{
teamLeague = inTeamLeague;
}
public void setTeamManager(string inTeamManager)
{
teamManager = inTeamManager;
}
public void setTeamNickname(string inTeamNickname)
{
teamNickname = inTeamNickname;
}
public void setTeamStadium(string inTeamStadium)
{
teamStadium = inTeamStadium;
}
public void setLeaguePosistion(int inLeaguePosistion)
{
leaguePosistion = inLeaguePosistion;
}
public void setLeaguePoints(int inLeagePoints)
{
leaguePoints = inLeagePoints;
}
public void setGamesPlayed(int inGamesPlayed)
{
gamesPlayed = inGamesPlayed;
}
public void setGoalDifference(int inGoalDifference)
{
goalDifference = inGoalDifference;
}
public void setPLayerNumber(int inPlayerNumber)
{
playerNumber = inPlayerNumber;
}
//end setters
}
}
任何幫助將不勝感激。謝謝。
你的getters/setters有點奇怪..你通常會使用像這樣的屬性:'公共字符串PropName {get {return _field; } set {_field = value; }}。在提到你的問題時,沒有理由不能像你對其他字段那樣在構造函數中包含'Image' obj。 – DGibbs
嗨! C#有一些稱爲屬性(和自動屬性)的東西。這是你應該谷歌的東西(根本不涉及你的問題,但與你發佈的代碼有關) –
你來自Java,不是嗎?我打電話告訴命名約定。我認爲最好使用屬性而不是getter和setter方法。 –