Kod:
public class Combination
{
List innerArray_ = new List();
public Combination()
{
this.DigitCount = 0;
this.Combinations = 0;
}
public int DigitCount { get; set; }
public int Combinations { get; set; }
public List GetCombinations()
{
if (DigitCount > 0)
{
//for (int i = 0; i < this.DigitCount; i++)
// GetCombinations(i.ToString(), i);
GetCombinations("", -1);
}
return this.innerArray_;
}
public List GetCombinations(int digitcount, int combinations)
{
this.DigitCount = digitcount;
this.Combinations = combinations;
return this.GetCombinations();
}
///
/// Kombinasyon hesaplamasını yapar
///
/// <param name="current">Şu anki işlenen veri</param>
/// <param name="index">İşlenen veri indexi</param>
private void GetCombinations(string current, int index)
{
string tmpcurrent = "";
for (int i = index + 1; i < this.DigitCount; i++)
{
tmpcurrent = current + i.ToString();
GetCombinations(tmpcurrent, i);
}
if (current.Length == this.Combinations)
this.innerArray_.Add(current);
}
}
5'in 2'li kombinasyonu için
Kod:
Combination com = new Combination();
List result = com.GetCombinations(5, 2);
Sııfı nasıl kullanacağınızı aşağıdaki linki takip ederek detaylı bir şekilde öğrenebilirsiniz.
Linkleri görebilmek için lütfen siteye üye olunuz!