我已經創建了兩個方法Radioactive_Sources,它們具有相同的名稱但參數不同,因爲它們用於不同的目的。一個只需要兩個參數,另一個需要六個參數。我如何使用這兩種方法,當我把它在不同的班級,我嘗試通過以下方式使用不同的參數創建相同的方法
namespace DABRAS_Software
{
...
public DefaultConfigurations()
{
ListOfSources = new List<Radioactive_Sources>(?) ; two arguments
ListOfSources_2 = new List<Radioactive_Sources>(?) ; six arguments
.....
--------------------------------
namespace DABRAS_Software
{
[Serializable]
public class Radioactive_Source
{
....
#region Constructor
public Radioactive_Source(string _Name, string _SerialNumber, string _Description, RadiationType _Type, EnergyBand _E, ulong _HalfLife, string _CertDate, int _CertActivity)
{
this.Name = _Name;
this.SerialNumber = _SerialNumber;
this.Description = _Description;
this.SourceType = _Type;
this.HalfLife = _HalfLife;
this.CertificationDate = _CertDate;
this.CertifiedActivity = _CertActivity;
this.Energy_Band = _E;
}
public Radioactive_Source(string _Name,RadiationType _Type)
{
this.Name = _Name;
this.SourceType = _Type;
}
#endregion
.............
@InseokBeak您需要了解[方法重載]之間的差值(http://csharpindepth.com/Articles/General/Overloading.aspx)和'你在哪裏創建屬性'名稱類Constructors', SerialNumber,...等'瞭解什麼是仿製藥關於列表其中'T'在你的情況是一個'類'請顯示所有相關的代碼。 –
MethodMan
這些不是單純的或常規的方法;他們是建設者。使用不同數量的參數不會使其成爲不同的類型。你有什麼只是兩種方式來創建一個同樣的事情的實例。您可能需要繼承 – Plutonix
您沒有兩種名爲Radioactive_Source的方法。你有一個類有兩個構造函數,這是不同的。 –