AwkwardMonkey
AwkwardMonkey

Reputation: 69

Take user input from one line and store into multiple variables

I'm having trouble finding this online but basically I want to know if its possible to use Console.ReadLine (); and write something like "dog cat cow" and store "dog" in a string variable, "cat" in another one, etc.

Upvotes: 1

Views: 44

Answers (1)

AwkwardMonkey
AwkwardMonkey

Reputation: 69

This is how I did it, it worked fine but is this the proper way of doing it?

        string s = "dog cat cow";
        string[] words = s.Split(' ');

        string i = words [0];
        string i1 = words [1];
        string i2 = words [2];

Upvotes: 2

Related Questions