我如何引用类?例如,我有一个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