D
d.s.
I've got an app with two classes, and one class (InventoryInfoClass)
is an object within the other class (InventoryItem). I'm running into
problems with trying to access (get/set) a private variable within the
included class (InventoryInfo) from the "including" class
(InventoryItem).
Here's the code, trimmed down. I've included ********* at the start
of the first line that's blowing up on me. I'm sure others that try
to access the invInfo.companyName field will blow up too.
Any help please?
------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace InventoryInfo
{
public class InventoryInfoClass
{
private string _companyName;
public InventoryInfoClass()
{
companyName = "";
}
public string companyName
{
get
{
return _companyName;
}
set
{
_companyName = value;
}
}
}
public class InventoryItem
{
private InventoryInfoClass invInfo;
private string _itemID;
public InventoryItem()
{
InventoryInfoClass invInfo = new InventoryInfoClass();
_itemID = "";
}
public string itemID
{
get
{
return _itemID;
}
set
{
_itemID = value;
}
}
public string companyName
{
get
{
********* return invInfo.companyName;
}
set
{
invInfo.companyName = value;
}
}
public void printInvItem()
{
Console.WriteLine("Company Name: {0}", this.companyName);
Console.WriteLine("Item ID: {0}", this.itemID);
Console.WriteLine("Press any key to continue");
Console.ReadLine();
}
}
class InvApp
{
static void Main(string[] args)
{
InventoryItem invItem = new InventoryItem();
invItem.printInvItem();
invItem.companyName = "C";
invItem.printInvItem();
}
}
}
is an object within the other class (InventoryItem). I'm running into
problems with trying to access (get/set) a private variable within the
included class (InventoryInfo) from the "including" class
(InventoryItem).
Here's the code, trimmed down. I've included ********* at the start
of the first line that's blowing up on me. I'm sure others that try
to access the invInfo.companyName field will blow up too.
Any help please?
------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace InventoryInfo
{
public class InventoryInfoClass
{
private string _companyName;
public InventoryInfoClass()
{
companyName = "";
}
public string companyName
{
get
{
return _companyName;
}
set
{
_companyName = value;
}
}
}
public class InventoryItem
{
private InventoryInfoClass invInfo;
private string _itemID;
public InventoryItem()
{
InventoryInfoClass invInfo = new InventoryInfoClass();
_itemID = "";
}
public string itemID
{
get
{
return _itemID;
}
set
{
_itemID = value;
}
}
public string companyName
{
get
{
********* return invInfo.companyName;
}
set
{
invInfo.companyName = value;
}
}
public void printInvItem()
{
Console.WriteLine("Company Name: {0}", this.companyName);
Console.WriteLine("Item ID: {0}", this.itemID);
Console.WriteLine("Press any key to continue");
Console.ReadLine();
}
}
class InvApp
{
static void Main(string[] args)
{
InventoryItem invItem = new InventoryItem();
invItem.printInvItem();
invItem.companyName = "C";
invItem.printInvItem();
}
}
}