-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

3
  • 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 and Writing the Perfect Question. Also, be sure to take the tour (you get a badge!). Commented Aug 2, 2021 at 17:19
  • Perhaps a Dictionary is what you are looking for? Commented Aug 2, 2021 at 17:19
  • 1
    Create a class Person and add instances of it in a collection like a List<Person>. You can find a person for exampe with LINQ: Person jack = allPersons.FirstOrDefault(p => p.Name == "Jack"); Commented Aug 2, 2021 at 17:26

1 Answer 1

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 };
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.