我知道這是一個愚蠢的問題,但我一直在自學C#,所以即時學習行話。作爲屬性的方法中,變量的正確名稱是什麼?
我的問題是:當我編寫方法時,當我需要它們共享相同的作用域時,我發現自己在方法的頂部聲明瞭對象和變量。這些類型的對象/變量是否有名字?我知道在一種方法之外宣佈他們將是屬性。
我的意思是示例代碼:我的問題是在Question區域中調用對象的內容。
public Label start_Ping(String target, string name, ref bool router)
{
#region [ Question ]
Label status_Label = new Label(); //Declare the label which will be dynamically created
Ping ping = new System.Net.NetworkInformation.Ping(); //Declare the ping object
PingReply reply = null; //Declare the pingReply object
byte[] buffer = new byte[100]; //Set the byte size
#endregion
if (name == "router")
{
try
{
reply = ping.Send(target, 50, buffer);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
if (reply.Status == IPStatus.Success)
{
router = true;
}
else
{
router = false;
return null;
}
}
try
{
...
在此先感謝。我理解這可能是很簡單=)
感謝您爲我清理。我正在努力添加一些評論,並不知道他們是否有適當的名字。再次感謝! – Botonomous 2012-01-28 16:42:36
另外,如果它們被聲明在方法之外,則稱它們爲** fields **。如果他們有getters和/或setter,他們只被稱爲**屬性**。除非你正在寫這個教C#的人,否則你不應該使用註釋或區域來標記你的本地變量。 – Maggie 2012-01-28 16:47:36
或除非他寫這個指向他的方法身體的具體部分... – BoltClock 2012-01-28 16:51:33