Accessing properties of one property of a class, directly

Hello,

I'm writing a class([b]MyClass[/b]) that have a subclass([b]Item[/b]) and a property of List of that subclass([b]List[/b]).
[b]MyClass[/b] have a property with name "[b]CurrentItem[/b]" that returns required Item.
My class is like this:
[code]
public class MyClass
{
private DataTable _mainDataTable;
private List _items;

public class Item
{
public Item()
{
}
public int Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public bool Enabled { get; set; }
}

private MyClass()
{
}

public DataTable MainDataTable
{
get
{
if (_mainDataTable == null && _items != null)
_mainDataTable = _items.ConvertToDataTable();
return _mainDataTable;
}
set { _mainDataTable = value; }
}
public List Items
{
get
{
if (_items == null && _mainDataTable != null)
{
_items = _mainDataTable.ConvertToListOfItems();
}
return _items;
}
set { _items = value; }
}
public int CurrentItemIndex { get; set; }
public Item CurrentItem
{
get
{
if (Items == null || Items.Count == 0 || CurrentItemIndex + 1 > Items.Count)
return new Item();
return Items[CurrentItemIndex];
}
}
}
[/code]
And the following code is an example of using it:
[code]
Myclass obj=new Myclass();
int id=obj.CurrentItem.Id;
[/code]
My problem is: I don't know that is there any way to access properties of [b]CurrentItem[/b] directly without writing [b]CurrentItem[/b]. like this code:

[code]
Myclass obj=new Myclass();
int id=obj.Id;
[/code]

Is there any way to do this?
Thanks

h.goli
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories