At last I was able to determine the problem I had the other nite and was able to solve it :). As I am moving all my previous codes in ASP.NET (in-line) to code-behind I face a lot of changes. But one good thing I really appreciate is I am really enjoying Bill Gates codes again huh!
I created my class as follows:
//Name: baseMenu.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace AbstractLayer
{
public class baseMenu
{
private string mobjName;
private string mobjLink;
private int mobjNew;
public string objName
{
set
{
this.mobjName = value;
}
get
{
return this.mobjName;
}
}
public string objLink
{
set
{
this.mobjLink = value;
}
get
{
return this.mobjLink;
}
}
public int objNew
{
set
{
this.mobjNew = value;
}
get
{
return this.mobjNew;
}
}
}
}
Then I've got error when I was trying to use it and declare an array of class:
AbstractLayer.baseMenu[] objMenus = new AbstractLayer. baseMenu[2];
objMenus[0].objName = "Adhoc #1";
The compiler gives me the error like this "Object reference not set to the instance of the object " and because I would say I am not yet as good as I am in other languages but have the foundation of OOP, I tried to look on the rule of the object. Of course I need to consult uncle Google and lot of forums.
Out of 10 visits , I found out 6 is telling me that my array is not initialized that is why is having a null value which gives the error.
It really makes me freaky a bit for whole day work until this dawn I managed to realised and understood (huh!) that I needed to declare every instance of the array.
objMenus[0] = new AbstractLayer.baseMenu();
objMenus[0].objName = "Adhoc #1";
then it follows ...
objMenus[nth] = new AbstractLayer.baseMenu();
objMenus[nth] = "Adhoc nth";
I really enjoy coding on C# as I wonder on how I will be more on C++ .NET Native code ... as I have few Java projects hanging around :)
Tuesday, May 22, 2007
Subscribe to:
Posts (Atom)