Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IDictionary<string, int> dict = new Dictionary<string, int>(); // where you would store all
- // the answers
- String prompt1 = "Enter a number ...";
- String prompt2 = "Enter number of IPv4 ..."; // and so on
- // initialize your stack
- Stack<string> prompts= new Stack<string>();
- prompts.Push(prompt1);
- prompts.Push(prompt2);
- while(prompts.Count != 0){
- String prompt = prompts.Peek(); // this doesn't remove the element from stack
- int input = 0;
- //display prompt to user and get input in input variable
- if(input>0){ // or whatever validation logic you want
- dict.Add(prompt, input);
- prompts.Pop(); //removes topmost element
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- int instances = CheckValues("Number of instances");
- int numofIpv4 = CheckValues("number of ipv4");
- int numofIpv6 = CheckValues("number of ipv6");
- //etc
- }
- private static int CheckValues(string input)
- {
- int parserValue = 0;
- string enteredValue = string.Empty;
- do
- {
- Console.WriteLine(input);
- enteredValue = Console.ReadLine();
- }
- while (!Int32.TryParse(enteredValue, out parserValue) || parserValue == 0);
- return parserValue;
- }
- }
- Regex _ipv4Regex = new Regex(@"bd{1,3}.d{1,3}.d{1,3}.d{1,3}b");
- if (ip.Matches(input))
- {
- // if valid
- }
Add Comment
Please, Sign In to add comment