-2

I want to create an array with identifiers To be more clear

Jack  Karen Tom Example Person
30    40    50  Age

Like this It does not be array necessarily but ı must search the age with name Using database is not fine for me, the age and name is just the simplification of my problem Thanks

Igor
  • 60,821
  • 10
  • 100
  • 175
  • 2
    Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. I suggest reading [*How do I ask a Good Question*](/help/how-to-ask) and [*Writing the Perfect Question*](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/). Also, be sure to take the [tour] (you get a badge!). – Igor Aug 02 '21 at 17:19
  • Perhaps a [`Dictionary`](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2) is what you are looking for? – Martin Aug 02 '21 at 17:19
  • 1
    Create a class `Person` and add instances of it in a collection like a `List`. You can find a person for exampe with LINQ: `Person jack = allPersons.FirstOrDefault(p => p.Name == "Jack");` – Tim Schmelter Aug 02 '21 at 17:26

1 Answers1

1

A very simple implementation could use a Dictionary like this:

using System;
using System.Collections.Generic;

public class Program
{
    public static void Main()
    {
        Dictionary<string, int> values = new Dictionary<string, int>
        {
            { "Jack", 30 },
            { "Karen", 40 },
            { "Tom", 50 },
        };
        
        Console.WriteLine(values["Jack"]);
    }
}

If you want to store more complex values, you can use a C# class:

public class Person
{
    public string Name { get; set; }
    public int Age { get; set; }
}

You can then create instances of this class and use them:

var person = new Person { Name = "Jack", Age = 30 };
Wouter de Kort
  • 39,090
  • 12
  • 84
  • 103