0

I have a class that reads all information from file, line by line, into the array Equipment. I would like to pass Equipment to the setEquipment method, and copy them to the setEquipment array.

Screenshot with the mistake: This is a screenshot with the mistake. What am I'm doing wrong?

string[] Equipment, Equipments;
public string[] InitialiseForm()
{
    Equipment = File.ReadAllLines(@"C:\\Temp\\Equipment.txt");
    Equipments = theEntity.setEquipment(Equipment);
    return Equipments;
}

This is the method

public string[] setEquipment(params string[] newEquipments)
{
    setEquipments = new string[newEquipments.Length];
    newEquipments.CopyTo(setEquipments, 0);

    return setEquipments;
}
6
  • In setEquipment, you return Equipments instead of setEquipments Commented Aug 26, 2017 at 23:58
  • sorry I've changed it. But it still doesn't work Commented Aug 26, 2017 at 23:59
  • theEntity is null in your screenshot. Where do you create a new instance of theEntity? Commented Aug 27, 2017 at 0:02
  • Thank you!!! I forget to create instance of theEntity. Commented Aug 27, 2017 at 0:06
  • 1
    OT: either use a @"..." (verbatim) string or use double (escaped) backslashes - you don't need both. Commented Aug 27, 2017 at 14:43

1 Answer 1

1

In your screenshot, theEntity is null. Remember to create an instance of the entity before calling its methods.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.