Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

belgium 251 PRG Prac

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Project_2._1
{
    internal class AntiStatic
    {
        #region Fields

        private string[,] array = new string[100, 3];
        private int counter = 2;

        #endregion Fields



        #region Enums

        private enum Menu
        {
            Add_Items = 1,
            SearchForItems,
            DisplayAllItems,
            Exit
        }

        #endregion Enums



        #region Methods

        private int Actions(int choosen)
        {
            Menu MenuChoice = new Menu(); MenuChoice = (Menu)choosen;
            switch (MenuChoice)
            {
                case Menu.Add_Items:
                    return 1;
                    break;

                case Menu.SearchForItems:
                    return 2;
                    break;

                case Menu.DisplayAllItems:
                    return 3;
                    break;

                case Menu.Exit:
                    return 4;
                    break;

                default:
                    return 5;
                    break;
            }
        }

        private void add_items()
        {
            counter += 1;
            Console.WriteLine("Item Name");
            array[counter, 0] = Console.ReadLine();
            Console.WriteLine("Item Model");
            array[counter, 1] = Console.ReadLine();
            Console.WriteLine("Price of Item");
            array[counter, 2] = Console.ReadLine();
        }

        private void displayAll()
        {
            Array obj = array;

            for (int i = counter; i > -1; i--)
            {
                Console.WriteLine(array[i, 0] + "          " + array[i, 1] + "         " + array[i, 2]);
            }
            Console.WriteLine("

Press a key to continue");
            Console.ReadLine();
        }

        private void searcheck()
        {
            Console.WriteLine("Model?");
            string a = Console.ReadLine();
            for (int i = counter; i > -1; i--)
            {
                if (array[i, 1] == a) { Console.WriteLine(array[i, 0] + "          " + array[i, 1] + "         " + array[i, 2]); }
            }
            Console.WriteLine("Press a key to continue");
            Console.ReadKey();
        }

        public void additems()
        {
            array[0, 0] = "Huawei";
            array[0, 1] = "2021";
            array[0, 2] = "1500";

            array[1, 0] = "Mara";
            array[1, 1] = "2019";
            array[1, 2] = "1000";

            array[2, 0] = "Samsung";
            array[2, 1] = "2020";
            array[2, 2] = "900";
        }

        public void menuDoisplay()
        {
            Console.Clear();
            Console.WriteLine("1. Add items
2. Search For Items
3. Display All items
.4 Exit");
        }

        public void MenuLoop()
        {
            int operations = 5;
            do
            {
                menuDoisplay();
                try
                {
                    operations = Actions(int.Parse(Console.ReadLine()));
                    if (operations != 5)
                    {
                        if (operations == 4)
                        {
                            break;
                        }
                        if (operations == 1)
                        {
                            add_items();
                        }
                        if (operations == 2)
                        {
                            searcheck();
                        }
                        if (operations == 3)
                        {
                            displayAll();
                        }
                    }
                }
                catch (Exception e)
                {
                    //Console.WriteLine(e);
                    //Console.ReadLine();
                }
            } while (operations != 4);
        }

        #endregion Methods
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# stack 
Csharp :: windows forms tablelayoutpanel scroll 
Csharp :: Smooth Sentences c# 
Csharp :: windows form toolbox enter key 
Csharp :: dotnet DB context register 
Csharp :: .net framework cheat sheet 
Csharp :: vb.net tostring numeric format string 
Csharp :: partial mvc 
Csharp :: c# listview 
Csharp :: c# get first word of string 
Csharp :: extension of c sharp 
Csharp :: c# array backwards 
Csharp :: c# count items in listbox 
Csharp :: how to get day name from datetimepicker in c# 
Csharp :: millie bobby brown age 
Csharp :: c# declaration definition 
Csharp :: how to backgrund c# red 
Csharp :: come controllare se textbox è vuota c# 
Csharp :: c# boundingbox text 
Html :: turn off autocomplete input html 
Html :: html include jquery 
Html :: connecting metamask to binance smart chain 
Html :: bootstrap 5 overflow 
Html :: meta colors html 
Html :: html head logo 
Html :: TypeError: Illegal invocation 
Html :: center iframe 
Html :: icons burger css font awesome 
Html :: how to link external css to html 
Html :: image src on error 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =