Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Accessing properties of one property of a class, directly

hgolihgoli Posts: 2Member
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.