Hi,
ich würde mir dafür erst einmal Klasse mit den benötigten Eigenschaften anstelle lokaler Variablen erstellen. Die einzelnen Ergebnisse der Abfragen speicherst Du dann dort und kannst im weiteren Programmverlauf auf diese Werte zugreifen.
public class Data
{
public String Gender { get; set; }
public List<Classification> Classifications { get; set; }
public Data()
{
this.FillClassifications();
}
private void FillClassifications()
{
this.Classifications = new List<Classification>();
this.Classifications.Add( new Classification( "m", 0, 20 ) );
this.Classifications.Add( new Classification( "m", 21, 25 ) );
this.Classifications.Add( new Classification( "m", 26, 30 ) );
this.Classifications.Add( new Classification( "w", 0, 20 ) );
this.Classifications.Add( new Classification( "w", 21, 25 ) );
this.Classifications.Add( new Classification( "w", 26, 30 ) );
}
}
public class Classification
{
public String Gender { get; set; }
public Int16 MinScore { get; set; }
public Int16 MaxScore { get; set; }
public Classification()
{
}
public Classification( String _gender, Int16 _minScore, Int16 _maxScore )
{
this.Gender = _gender;
this.MinScore = _minScore;
this.MaxScore = _maxScore;
}
}
Verwenden kannst Du die dann bspw. so:
class Program
{
static void Main( string[] args )
{
Data data = new Data();
Console.WriteLine( "Bitte Geschlecht eingeben [m|w]:" );
data.Gender = Console.ReadLine();
Console.WriteLine( $"Geschlecht: {data.Gender}" );
foreach ( Classification item in data.Classifications.Where( f => f.Gender == data.Gender ) )
{
Console.WriteLine( $"Klassifizierung: {item.MinScore} - {item.MaxScore}" );
}
Console.ReadKey();
}
}
Gruß, Stefan
Microsoft MVP - Visual Developer ASP/ASP.NET (2001-2018)
https://www.asp-solutions.de/ - IT Beratung, Softwareentwicklung, Remotesupport