-2

Very basic question here, as I'm just getting into things. Basically, I'm stuck on how to look up info from an instance of a class based on user input in C#.

I'm working on a personal practice program that matches two members together. Essentially, I've created a class with a member number and an array of previous connections.

class opsNextMember
{ // Creates a member
    public int memberNumber;
    public int[] previousConnections;

As part of this program, I want to allow for a basic input of two member numbers and then look up the first number to see if the second is in its array of previous connections and return true/false.

I've gotten as far as getting the two numbers from the user but I can't figure out how to look up an instance of the member class based on that number.

static bool PreviousConnection()
    { // Tells you if two members have been previously connected based on their member number.
        Console.WriteLine ("Enter first member number");
        int member1 = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine ("Enter second member number");
        int member2 = Convert.ToInt32(Console.ReadLine());
    }

Any help would be much appreciated by a new beginner, thank you.

1
  • You can use the Contains() method to check whether an array or other collection contains a specific value. See duplicate. Commented Mar 3, 2021 at 19:35

1 Answer 1

0

You can find this number using the Contains () method

For example:

var member = new opsNextMember();
var hasConnected = member.previousConnections.Contains(<member id>);
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.