C# convert value of variable to variable

class Program
{
    struct St_test
    {
        public string f_name;
        public string l_name;
        public int age;
        public string email;
    }
    static void proced(int number)
    {
        St_test s = new St_test();
        Console.WriteLine("Enter the first name :");
        s.f_name = Console.ReadLine();
        Console.WriteLine("Enter the last name :");
        s.l_name = Console.ReadLine();
    agee:
        Console.WriteLine("Enter the age :");
        try { s.age = int.Parse(Console.ReadLine()); }
        catch { Console.WriteLine("You enterd viod age"); goto agee; }
        Console.WriteLine("Enter the e_mail :");
        s.email = Console.ReadLine();
    }
    static void Main(string[] args)
    {
        int num;
        nume:
        Console.WriteLine("enter the count of people you would like to store");
        try {  num = int.Parse(Console.ReadLine()); }
        catch { Console.WriteLine("you enterd void number"); goto nume; }
        for (int i = 0;  i < num;  i++)
        {
            proced(num);
        }

I want to input many of (S) to every number (num) of people.

How to repeat the procedure (proced) and every repeat the (s) variable has new name.

If I write in the procedure (proced) the next :

string r = "s" + number;

how to convert the resulted string (r) to variable to use it instead of (s) variable for each loop

Jon Skeet
people
quotationmark

You can't (easily, anyway) access variables by name like that - but there's a much better solution, which is to create a collection of some kind - an array or a list, for example.

I would suggest:

  • Changing your St_test struct:
    • Make it a non-nested type
    • Give it a clearer name (e.g. Person)
    • Make it a class
    • Don't expose fields - expose properties
    • Potentially make it immutable, taking all the values in the constructor
  • Changing your proced method:
    • Make it return a new Person
    • Change the name to follow .NET naming conventions
    • Stop using goto
    • Factor out the "request an integer from the user" into a method
  • Changing your Main method:
    • Create a List<Person>
    • Repeatedly call what used to be called proced. but add the return value into the list

You'll end up with code something like this - but don't blindly copy it. Make sure you understand everything that's happening here.

using System;
using System.Collections.Generic;

public sealed class Person
{
    public string FirstName { get; }
    public string LastName { get; }
    public int Age { get; }
    public string Email { get; }

    public Person(string firstName, string lastName, int age, string email)
    {
        // TODO: Validation
        FirstName = firstName;
        LastName = lastName;
        Age = age;
        Email = email;
    }
}

public class Test
{
    private static Person CreatePersonFromUserInput()
    {
        Console.WriteLine("Enter the first name:");
        string firstName = Console.ReadLine();
        Console.WriteLine("Enter the last name:");
        string lastName = Console.ReadLine();
        Console.WriteLine("Enter the age:");
        int age = RequestInt32();
        Console.WriteLine("Enter the email address:");
        string email = Console.ReadLine();
        return new Person(firstName, lastName, age, email);
    }        

    private static int RequestInt32()
    {
        string text = Console.ReadLine();
        int ret;
        while (!int.TryParse(text, out ret))
        {
            Console.WriteLine("Invalid value. Please try again.");
            text = Console.ReadLine();
        }
        return ret;
    }

    private static void Main()
    {
        Console.WriteLine("Enter the count of people you would like to store:");
        int count = RequestInt32();
        List<Person> people = new List<Person>();
        for (int i = 0; i < count; i++)
        {
            people.Add(CreatePersonFromUserInput());
        }
        // Just to show them...
        foreach (Person person in people)
        {
            Console.WriteLine(
                $"First: {person.FirstName}; Last: {person.LastName}; Age: {person.Age}; Email: {person.Email}");
        }
    }

}

people

See more on this question at Stackoverflow