Okay so I hope the title makes sense but I'll explain a litte more indepth. Right now i have an object that consists of multiple forms of data (strings, int, and a boolean array). The object array looks like this (sorry for all the clutter I had it looking nice, then accidently hit back and don't want to retype it all)

namespace WorkScheduleApp_V2_2v3
 {
//==================================================================================================================
  public class Employee
   {
    bool active;
    string ID;
    string name;
    string DOB;
    int age;
    string position;
    bool [] shiftType;
//-----------------------------------------------------------------------------------------------------------------
    public Employee (bool active, string ID, string name, string DOB, int age, string position, bool [] shiftType)
     {
      this.active = active;
      this.ID = ID;
      this.name = name;
      this.DOB = DOB;
      this.age = age;
      this.position = position;
      this.shiftType = shiftType;
     }
//-----------------------------------------------------------------------------------------------------------------
    public void inActive (bool input) //if they are active or on leave
     {
      active = input;
     }
//-----------------------------------------------------------------------------------------------------------------
    public void inID (string input) //the employee's ID (out last 4 SS digits)
     {
      ID = input;
     }
//-----------------------------------------------------------------------------------------------------------------
    public void inName (string input) //the employee's name
     {
      name = input;
     }
//-----------------------------------------------------------------------------------------------------------------
    public void inDOB (string input) //the employee's DOB
     {
      DOB = input;
     }
//-----------------------------------------------------------------------------------------------------------------
    public void inAge (int input) //the employee's age
     {
      age = input;
     }
//-----------------------------------------------------------------------------------------------------------------
    public void inPos (string input) //the employee's position
     {
      position = input; 
     }
//-----------------------------------------------------------------------------------------------------------------
    public void inShiftTypes (bool [] input) //imports the whole shiftType array for the employee's shift types
     {
      shiftType = input;
     }
//-----------------------------------------------------------------------------------------------------------------
    public void inShiftType_Spec (bool input, int i) //imports just 1 part of the shiftType array
     {
      shiftType [i] = input;
     }
//-----------------------------------------------------------------------------------------------------------------      
    public bool isActive ()
     {
      return active;
     }
//-----------------------------------------------------------------------------------------------------------------
    public string isID ()
     {
      return ID;
     }
//-----------------------------------------------------------------------------------------------------------------
    public string isName ()
     {
      return name;
     }
//-----------------------------------------------------------------------------------------------------------------
    public string isDOB ()
     {
      return DOB;
     }
//-----------------------------------------------------------------------------------------------------------------
    public int isAge ()
     {
      return age;
     }
//-----------------------------------------------------------------------------------------------------------------
    public string isPos ()
     {
      return position;
     }
//-----------------------------------------------------------------------------------------------------------------
    public bool [] isShiftTypes ()
     {
      return shiftType;
     }
//-----------------------------------------------------------------------------------------------------------------
    public bool isShiftTypes_Spec (int i)
     {
      return shiftType [i];
     }
//-----------------------------------------------------------------------------------------------------------------
   }
//==================================================================================================================
 }

Anyway as you can see this object contains a boolean array as I stated before. Well what I would like to know is if there is a way to resize this array?

I know how to resize most arrays with the line

Array.Resize(ref array, size);

But that won't work for this. I was think of calling isShiftType() and assigning the array in the object to another array, the calling inShiftType where I would pass in a null (this I assume would clear out old array in the object) and then call inShiftType again passing in the newly resized array (that I stored with inShiftType() and then used the Array.Resize() command).

There is two issues with this though, one is I am not sure if this will even work, and two this seems like very bad coding (very messy and not needed).

Any help would be greatly appreciated, again sorry if this seems a little messy and rushed, as I said before I was almost done typing and accidently had the page go back on me (plus I am rushed for time)

Recommended Answers

All 6 Replies

IMO you better use properties, something like:

public bool active{ get; set; }

instead of

public void inActive (bool input) //if they are active or on leave    
{      
    active = input;     
}

in your constructor this would give:

public Employee (bool active, string ID, string name, string DOB, int age, string position, bool [] shiftType)     
{      
    this.active = active;
//etc

Use a List, List<bool> for your array problem.

When ever you are not sure how long is gonna be the array, you never use a "basic" arrays like: string[], int[], bool[], or what ever of these kind.
ddanbe has perfectly right, use a generic list, which is in my opinion my far the best type of array. If offers so many posiblilities to work with.

or you can even use an ListArray - for this you have to create a new namespace (System.IO)

Mitja

Thanks guys, I was actually wondering about using an ArrayList, partially because it's the greatness of a Queue or Stack as well as an array.

Also ddanbe you mind showing me this get, set thing alittle more in depth

What I used is called autoimplemented property syntax (let the compiler do the work.) Study this example from MSDN.
To use a normal property see this
If you are sometimes confused with C# (as I stil am :-O ) just ask more questions, we are here to help :)

Well I converted it over to an ArrayList, all seems well I still need to actually fix the error I was having that needed the ArrayList, but so far so good. Thanks for the help, I can't believe I spaced on that

and ddanbe I'll have to look on coverting it over to a get, set but it will have to wait I need to get this program fully working before I start doing upgrades

I can live with your decision :)
But believe me, properties can make your life alot easier.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.