0
namespace OO_Assign_2_eDepot_
{
    public partial class Driver
    {
        int driver_size = 1;
        public string[] d_username = new string[driver_size] {"john"};     
        public string[] d_password = new string[driver_size] { "pass1" };
    }
}

driver.size is not recognized as the variable size in the arrays

  • 6
    do you mean driver_size instead of driver.size ? – auburg Apr 06 '16 at 12:27
  • You are using both size and element syntax for initializing the array. What size of the array do you expect? – IS4 Apr 06 '16 at 12:27
  • 5
    First off, stop everything and grab a copy of CLR Via C#. Skip the two chapters and read. You've got no idea what's going on--spend a couple hours and learn. Also, throw away all the underscores. –  Apr 06 '16 at 12:28
  • yes I mean't driver_size* – user3597671 Apr 06 '16 at 12:28
  • Please update your question then – auburg Apr 06 '16 at 12:29
  • I want to be able to extend the array within the console if necessary, e.g. if something is true driver_size += 1; – user3597671 Apr 06 '16 at 12:30
  • What is the error message you're getting. – Lasse V. Karlsen Apr 06 '16 at 12:31
  • A driver should be able to have multiple names, or you want an array of `Driver`? – IS4 Apr 06 '16 at 12:31
  • error, "The driver does not exist in the current context" – user3597671 Apr 06 '16 at 12:32
  • I want an array of drivers* – user3597671 Apr 06 '16 at 12:32
  • Check this one: http://stackoverflow.com/questions/14439231/a-field-initializer-cannot-reference-the-nonstatic-field-method-or-property – blfuentes Apr 06 '16 at 12:32
  • 1
    If you want an array of drivers and change its size later, consider using `List`. – IS4 Apr 06 '16 at 12:34
  • Does username and password belong together? If yes, then why have it in two completely separate arrays with the only connection being the index? Combine them in a class and store objects of that class in an array. Also, why an array? If you don't know a very good answer to that, go with a typed list. Next, did you think, changing `driver_size` at any point during runtime (after instantiating the arrays) would automatically adjust the size of the arrays? Nope, would not have happened. Make sure you understood the difference between reference types and value types. – Corak Apr 06 '16 at 12:42

1 Answers1

0

Choose one:

public partial class Driver 
{ 
    int driver_size = 1; 
    // Set size
    public string[] d_username = new string[driver.size]; 
    // Set value
    public string[] d_password = new string[] { "pass1" }; 
}
Toxantron
  • 2,218
  • 12
  • 23