Структуры. Определить имя мужчины с ростом x - C#
Формулировка задачи:
Опишите функцию Name(G), определяющую имя мужчины из группы
G с ростом x.
Помогите написать функцию.
struct G
{
public string name;
public bool male;
public int height;
public int[] group;
public G(string name,int height):this()
{
}
на помощь!!!
Решение задачи: «Структуры. Определить имя мужчины с ростом x»
textual
Листинг программы
using static System.Console;
struct Man
{
public string name;
public int height;
public Man(string n,int h) { name = n;height = h; }
public static bool GetName(Man[] G, int x,out string s)
{
s = null;
foreach (Man m in G)
if (m.height == x)
{
s = m.name;
return true;
}
return false;
}
}
static class test
{
static void Main()
{
Man[] group = {new Man("Lexxxa",150),new Man("Vonny",170),new Man("Mixer",200) };
string name;
int a = 170;
WriteLine("есть ли в группе человек с ростом {0} ?",a);
if (Man.GetName(group, a, out name))
WriteLine("есть, его имя - " + name);
else WriteLine("нету...");
ReadKey(true);
}
}