private static void MainLoop() { int[] tab = Tables.GenerateRandomIntTable(ReadValues.GetUint("table size= ")); DisplayTable(tab); BubbleSort(tab); DisplayTable(tab); }
private static void PopulateTable(int[] tab) { for (int i = 0; i < tab.Length; i++) { tab[i] = ReadValues.GetInt($"tab[{i}]= "); } }
private static Gender GetGender() { char input = ReadValues.GetCharacter("Type 'M' for Male, 'F' for female "); while (true) { switch (input) { case 'M': return(Gender.MALE); case 'm': return(Gender.MALE); case 'F': return(Gender.FEMALE); case 'f': return(Gender.FEMALE); default: Console.WriteLine($"Wrong input ({input}) try again!"); input = ReadValues.GetCharacter("Type 'M' for Male, 'F' for female."); break; } } }
private static void MainLoop() { int size = ReadValues.GetInt("tab size= "); int[] tab = new int[size]; PopulateTable(tab); DisplayHistogram(GetHistogram(tab)); }
private static Address GetAddress() { Address address = new Address(); address.City = ReadValues.GetString("Provide City: "); address.Street = ReadValues.GetString("Provide street: "); address.HouseNo = ReadValues.GetInt("Provide house number: "); return(address); }
static void Main(string[] args) { uint n = ReadValues.GetUint("n= "); int[] tab = new int[n]; PopulateTable(tab); string tabStr = string.Join(",", tab); Console.WriteLine($"For number: {tabStr} the avarage= {GetAverage(tab)}"); }
private static Contact GetContact() { Contact contact = new Contact(); contact.FirstName = ReadValues.GetString("Provide first name: "); contact.LastName = ReadValues.GetString("Provide last name: "); contact.PhoneNo = ReadValues.GetInt("Provide phone number: "); contact.Gender = GetGender(); contact.Address = GetAddress(); return(contact); }
static void Main(string[] args) { int[] tab = new int[5]; for (int i = 0; i < tab.Length; i++) { tab[i] = ReadValues.GetInt($"tab[{i}] = "); } Console.Write("Reversed tab= "); for (int i = tab.Length - 1; i > -1; i--) { Console.Write($"{tab[i]} "); } Console.WriteLine(); }
private static void MainLoop() { uint start; uint end; do { Console.WriteLine("--- SIEVE OF ERATOSTHENES ---"); Console.WriteLine("Provide range:"); start = ReadValues.GetUint("Range start= "); end = ReadValues.GetUint("Range end= "); if (start > 1 && (start < end)) { break; } Console.WriteLine("Wrong input. Try again"); Console.WriteLine("Press any key to continue"); Console.ReadKey(); Console.Clear(); } while (true); DisplayPrimes(start, end); }
/// <summary>Reads and converts the JSON to type <typeparamref name="T" />.</summary> /// <param name="reader">The reader.</param> /// <param name="typeToConvert">The type to convert.</param> /// <param name="options">An object that specifies serialization options to use.</param> /// <returns>The converted value.</returns> /// <exception cref="JsonException">Element was not a string or could not identify the JSON value as a known enum value.</exception> public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { EnsureMap(); string str; if (reader.TokenType != JsonTokenType.String) { if (typeToConvert.GetCustomAttribute <FlagsAttribute>() != null && reader.TokenType == JsonTokenType.StartArray) { reader.Read(); // waste the start array var values = new List <T>(); while (reader.TokenType != JsonTokenType.EndArray) { str = reader.GetString(); if (!ReadValues.TryGetValue(str, out var immediate)) { throw new JsonException($"Could not find appropriate value for {str} in type {typeToConvert.Name}"); } values.Add(immediate); reader.Read(); } reader.Read(); // waste the end array return(values.Aggregate(Aggregator)); } throw new JsonException("Expected string"); } str = reader.GetString(); return(ReadValues.TryGetValue(str, out var value) ? value : throw new JsonException($"Could not find appropriate value for {str} in type {typeToConvert.Name}")); }
private static void MainLoop() { bool exit = false; int input; _size = ReadValues.GetUint("Provide number of contacts: "); _contacts = new Contact[_size]; while (!exit) { DisplayMenu(); input = ReadValues.GetInt("Select option 1-3: "); switch (input) { case 1: AddNewContact(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case 2: DisplayContacts(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case 3: Console.WriteLine("Exiting ..."); exit = true; break; default: Console.WriteLine($"Wrong input ({input}). Try again."); break; } Console.Clear(); } }