我如何引用類?例如,我有一個Price.cs
來計算項目的支出,但我不能使用任何Windows在我Price.cs
形成控制和必須引用我Main.cs
爲了使用屬性和控制。對不起,如果我聽起來很混亂。英語不是我的主要語言。如何引用類在另一個類C#Windows窗體
Main.cs:
private float? PricePlacement()
{
if (serviceDesc.Text != "Multiple")
{
if (serviceDesc.Text == "Phone Repair")
{
textBlock_Price.Text = "$20.00 + Parts";
return 20.00f;
}
if (serviceDesc.Text == "Virus Removal")
{
textBlock_Price.Text = "$10.00";
return 10.00f;
}
if (serviceDesc.Text == "Hardware Repair/Installation")
{
textBlock_Price.Text = "$10.00";
return 10.00f;
}
if (serviceDesc.Text == "Software Installation")
{
textBlock_Price.Text = "$5.00";
return 5.00f;
}
textBlock_Price.Text = "$0.00";
return 0f;
}
else if (serviceDesc.Text == "Multiple")
{
//TODO: Implement a function to check if an item on the itemList is checked or not
textBlock_Price.Text = "$-.--";
return null;
}
return 0f;
}
Price.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TicketingSystem
{
class Price
{
}
}
不能清楚地理解你正在嘗試做什麼,但是你可以在Main.cs中創建一個'class Price'實例,如 'class Main {private price price; ... } – AbdullahRazzaki
您的應用中的依賴關係通常應該以您的實體(比如'Price',它不依賴於任何東西)開始,繼續所謂的「業務邏輯」(即對實體進行操作的代碼,無知任何用戶界面,只依賴於實體),然後進入「演示」(一個控制檯應用程序,Windows窗體,網頁,取決於實體和業務邏輯)。所以,如果一個'Price'需要知道一個GUI,那麼你的方向是完全錯誤的。 – Groo