Start New Discussion within our Software Development Community

I am having some trouble figuring out exactly how to do this, here is an example,

public static String[] myArray = new String[40];

private void tbSomeInfo_TextChanged(object sender, EventArgs e)
        {
            StepNumber1 sn1 = new StepNumber1();
            sn1.DoSomething(ref myArray);
        }

public class StepNumber1
{
        public void DoSomething(ref myArray)
{
        int start = 3;
        int TempStart = 6;

        CallPrivateFunction(ref myArray, start, tempStart);
}

        private void CallPrivateFunction(ref myArray, int start, int tempStart)
{
        String[] tempArray = myArray[start].split(','); // This line buggers up
}
}

I keep getting Object reference not set to an instance of an object error. Properties seems to be the way to go but since im still learning c# i would like to know why exactly this does not work, ty.

I have learned the error, I was trying to split a null line, case closed.

Great! Did you compiled this code?

Array is reference type so you could avoid ref declaration.

However below declaration create 40 reference variables which are initilized with null.

public static String[] myArray = new String[40];

So you got an error - Object reference not set to an instance of an object error. Replace split with Split.

String[] tempArray = myArray[start].split(','); // This line buggers up

Parameter missing type name.

public void DoSomething(ref string []myArray){
        int start = 3;
        int tempStart = 6;
        CallPrivateFunction(ref myArray, start, tempStart);
}
private void CallPrivateFunction(ref string []myArray, int start, int tempStart)
{
        String[] tempArray = myArray[start].split(','); // This line buggers up
}
This article has been dead for over six months. Start a new discussion instead.