我需要調用一些方法從一個類到另一個類在C#中。它不同於其他答案,因爲我似乎找不到具體的答案,我正在尋找。如何從一個類調用方法到另一個類
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace IT2127P2_150538B
{
public partial class InputForm : Form
{
const double cupCakePrice = 1.50;
int noOfCupcakes, loyaltyPoints;
double TotalPrice;
int[] price = new int[15];
public InputForm()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Form Summaryform = new SummaryForm();
Summaryform.ShowDialog();
noOfCupcakes = int.Parse(txtNoOfCupcakes.Text);
TotalPrice = noOfCupcakes * cupCakePrice;
if (txtMemId.Text != "")
{
if (noOfCupcakes/2 > 0)
{
loyaltyPoints = (((noOfCupcakes - 1)/2) * 3) + 1;
}
else
{
loyaltyPoints = (noOfCupcakes/2) * 3;
}
}
else
{
loyaltyPoints = 0;
}
}
}
}
}
上面的代碼是計算完成的主要類。現在我必須在下面的代碼中顯示紙杯蛋糕的數量,忠誠度積分和總蛋糕價格。我的問題是,我似乎無法找到一種方法將主要類中的變量調用到次要類中。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace IT2127P2_150538B
{
public partial class SummaryForm : Form
{
const double cupcakePrice = 1.50;
public SummaryForm()
{
InitializeComponent();
}
private void SummaryForm_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
_「現在我必須在下面的代碼中顯示紙杯蛋糕的數量,忠誠度積分和總的蛋糕價格」_ - - 好吧?你有問題嗎?你有什麼特別的問題?你的問題幾乎肯定是https://stackoverflow.com/questions/1665533/communicate-between-two-windows-forms-in-c-sharp的重複,但如果你至少要解釋一下你真的在問。這個問題很不明確。 –