コード例 #1
0
        static void Main(string[] args)
        {
            for (; ;)
            {
                string        users_input, output;
                int           param_index   = 0;
                bool          check         = false;
                List <string> value_strings = Lesson2.Parse();
                List <string> param         = Lesson2.Param(value_strings);

                do
                {
                    Console.WriteLine("Please,input parametr which has your interest");
                    users_input = Console.ReadLine();
                    foreach (string s in param)
                    {
                        if (users_input == s)
                        {
                            check = true;
                            break;
                        }
                        param_index++;
                    }
                    if (check == false)
                    {
                        Console.WriteLine("Your input is incorrect.Please, retry");
                        param_index = 0;
                    }
                }while (check == false);


                output = value_strings.ElementAt(param_index);
                Console.WriteLine("Result:\n" + $" {output}");
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            string firstNum  = args[0];
            string secondNum = args[1];
            string result    = new Lesson2().Sum(firstNum, secondNum);

            Console.WriteLine($"{firstNum} + {secondNum} = {result}");
        }
コード例 #3
0
        static void Main(string[] args)
        {
            bool   comment_in_value_string;
            int    comment_index = 0;
            string user_changes_input;
            int    zeros_beetween_comment_and_value;

            for (; ;)
            {
                for (; ;)
                {
                    string getORset = "";
                    Console.WriteLine("If you want to see parametres values print get\nIf you want to change parametres values print set");

                    getORset = Console.ReadLine();
                    if (getORset == "get" || getORset == "set")
                    {
                        break;
                    }
                    Console.WriteLine("Print get or set");
                }
                zeros_beetween_comment_and_value = 0;
                comment_in_value_string          = false;
                string        users_input, output = "", swap = "";
                string[]      allstrings    = File.ReadAllLines("conf");
                int           param_index   = 0;
                bool          check         = false;
                List <string> value_strings = Lesson2.Parse(allstrings);
                List <string> param         = Lesson2.Param(value_strings);

                Console.WriteLine("------------------------------------");

                do
                {
                    param_index = 0;
                    Console.WriteLine("Please,input parametr which has your interest");
                    users_input = Console.ReadLine();
                    foreach (string s in param)
                    {
                        if (users_input == s)
                        {
                            check = true;
                            break;
                        }
                        param_index++;
                    }
                    if (check == false)
                    {
                        Console.WriteLine("Your input is incorrect.Please, retry");
                    }
                    //  param_index = 0;
                }while (check == false);


                output = value_strings.ElementAt(param_index);
                if (output.Contains(';'))
                {
                    comment_in_value_string = true;
                    comment_index           = output.IndexOf(';');
                }
                else if (output.Contains('#'))
                {
                    comment_in_value_string = true;
                    comment_index           = output.IndexOf('#');
                }
                for (int i = comment_index - 1; i > -1; i--)
                {
                    if (Convert.ToString(output[i]) == " ")
                    {
                        zeros_beetween_comment_and_value++;
                    }
                    else
                    {
                        break;
                    }
                }
                switch (getORset)
                {
                case "get":
                    Console.WriteLine(comment_in_value_string == false ? "Result:\n" + $" {output}" : "Result:\n" + $" {output.Remove(comment_index)}");
                    break;

                case "set":
                    Console.WriteLine("Input updated info:");
                    swap = param.ElementAt(param_index) + " ";
                    for (; ;)
                    {
                        user_changes_input = Console.ReadLine();
                        if (user_changes_input.Contains("#") || user_changes_input.Contains(";"))
                        {
                            Console.WriteLine("You use prohibited symbols");
                        }
                        else
                        {
                            break;
                        }
                    }

                    swap += user_changes_input;
                    if (param.ElementAt(param_index).Length + 1 == swap.Length)
                    {
                        swap = swap.Remove(swap.Length - 1);
                    }
                    for (int i = 0; i < zeros_beetween_comment_and_value; i++)
                    {
                        swap += " ";
                    }
                    if (comment_in_value_string == true)
                    {
                        swap += output.Substring(comment_index);
                    }


                    for (int i = 0; i < allstrings.Length; i++)
                    {
                        if (output == allstrings[i])
                        {
                            allstrings[i] = swap;
                            File.WriteAllLines("conf", allstrings);
                            break;
                        }
                    }
                    break;
                }
                /////////////////
                comment_in_value_string          = false;
                comment_index                    = 0;
                user_changes_input               = "";
                zeros_beetween_comment_and_value = 0;
                ////////
                /// value_strings = null;
                // allstrings = null;
            }
        }