I am new to C#, & so I am in the process of teaching myself. I come from a C/C++ (& some C++/CLI) background.
The following are code snippets showing the code where the error occurs (during debug).
There is what might look like bad code, but I’ve been trying to instantiate the “path” String in different ways to see if the error goes away – so that’s why it looks so clumsy & also why some of
it might not really make sense, since this is just some dummy code, & so not the final code I am going to actually use.
What I don’t understand is the fact that when this event gets executed, the “path” String already contains a string containing an actual
path, however, it results in an error as if this “path” was actually either NULL or empty & thus resulting in the “NullReferenceException” exception being thrown & hot handled. Thanks.
{
public class
Controller
{
public bool LogFileIsLegal(String filename)
{
bool isLegal = false;
int len = filename.Length;
if (len > 0) isLegal =
true;
return isLegal;
}
}
}
namespace WindowsFormsApplication1
{
public partial
class Form1 :
Form
{
public Controller pC;
public Form1()
{
InitializeComponent();
}
private void Start_Button_Click(object sender,
EventArgs e)
{
String path =
new String(' ',512);
path = Location_ComboBox.Text;
String filename =
"TestFile";
if(String.IsNullOrEmpty(path) ==
false)
{
if (pC.LogFileIsLegal(path)) <<== ERROR occurs here ==
{
Console.WriteLine("Got this far.");
}
}
}
namespace Process_Y