E
E
Evgeny Semashko2020-09-16 00:28:24
C++ / C#
Evgeny Semashko, 2020-09-16 00:28:24

How to display Dictionary values?

There is a dictionary with added values

static Dictionary<(int, bool), string> Status = new Dictionary<(int, bool), string>();


        static Generator()
        {       
            Status.Add((1, false), "IsOnlyNumbers");
            Status.Add((2, false), "IsOnlyAlphabetLower");
            Status.Add((3, false), "IsOnlyAlphabetUpper");
            Status.Add((4, false), "IsOnlySymbols");

        }


I need to output all these values ​​to the console in the formatting of the view.
5f61306b68092134960310.png
That is, further down should be: 2 - IsOnlyAlphabetLower: False, etc.
What happened to me
5f6130cbeecc3286002519.png
happened, of course, this is because of this code:
foreach (var outer in Status.Keys)
            {
                foreach (var inner in Status.Values)
                {
                    if (outer.Item2 == false)
                    {
                        Console.Write($"{outer.Item1} - {inner}: ");
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write($"{outer.Item2}\n");
                        Console.ResetColor();
                    }
                }
            }

How can I get the following output from such a dictionary:
1 - IsOnlyNumbers: False
2 - IsOnlyAlphabetLower: False
3 - IsOnlyAlphabetUpper: False
4 - IsOnlySymbols:

False

All code

using System;
using System.Collections.Generic;
using System.Linq;

namespace Lab_Generator
{
  
    class Program
    {
        
        static void Main(string[] args)
        {

            Generator.GetInfoTypes();

            Generator.SetTypePassword();
            
            Console.ReadLine();
        }
        
    }

    
    class Generator
    {
        static Dictionary<(int, bool), string> Status = new Dictionary<(int, bool), string>();


        static Generator()
        {       
            Status.Add((1, false), "IsOnlyNumbers");
            Status.Add((2, false), "IsOnlyAlphabetLower");
            Status.Add((3, false), "IsOnlyAlphabetUpper");
            Status.Add((4, false), "IsOnlySymbols");

        }
       
      public static void GetInfoTypes()
      {
            foreach (var outer in Status.Keys)
            {
                foreach (var inner in Status.Values)
                {
                    if (outer.Item2 == false)
                    {
                        Console.Write($"{outer.Item1} - {inner}: ");
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write($"{outer.Item2}\n");
                        Console.ResetColor();
                    }
                }
            }
        }
     
      public static void SetTypePassword()
      {
           
      }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mbjuggernaut, 2020-09-16
@evgenysemashko

foreach (var stat in Status)
{
if (stat.Key.Item2 == false)
{
Console.Write($"{stat.Key.Item1} - {stat.Value}: ");
...
...
}
}
In general, it's easy to track down if you debug it.)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question