struct
Last updated:
8/23/2020
⁃
Difficulty:
Easy
Create a C# program that asks the user for their name and age. You must save them in a struct
data structure and then greet the user using their name.
Input
Jonny
20
Output
Hello, Jonny!
Solution
using System;
public class Struct
{
public struct Person
{
public string Name;
public int Age;
}
public static void Main(string[] args)
{
Person p = new Person();
p.Name = Console.ReadLine();
p.Age = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Hello, {0}!", p.Name);
}
}