mercredi 28 juin 2017

Can C# decide what variable to assign a value to? [duplicate]

This question already has an answer here:

Is there a way to write code so that when a user gives input, either a string or a number, that the program will choose the most appropriate of the available variables that have been declared?

Pseudocode example:

static void Main()
{
    int A;
    string B;

    Console.Write("enter something: ");

    if (user enters a number)
        A = int.Parse(Console.ReadLine());
    else
        B = Console.ReadLine();
}

Aucun commentaire:

Enregistrer un commentaire