Click here to Skip to main content
15,887,350 members
Home / Discussions / C#
   

C#

 
Questionasp.net enterprise application Pin
Member 882441719-Sep-13 8:26
Member 882441719-Sep-13 8:26 
AnswerRe: asp.net enterprise application Pin
Dave Kreskowiak19-Sep-13 13:22
mveDave Kreskowiak19-Sep-13 13:22 
GeneralRe: asp.net enterprise application Pin
Member 882441721-Sep-13 8:30
Member 882441721-Sep-13 8:30 
GeneralRe: asp.net enterprise application Pin
Dave Kreskowiak21-Sep-13 12:10
mveDave Kreskowiak21-Sep-13 12:10 
QuestionOPOS driver Pin
kropek19-Sep-13 2:02
kropek19-Sep-13 2:02 
AnswerRe: OPOS driver Pin
kropek19-Sep-13 2:02
kropek19-Sep-13 2:02 
AnswerRe: OPOS driver Pin
OriginalGriff19-Sep-13 3:46
mveOriginalGriff19-Sep-13 3:46 
QuestionAccessing properties of one property of a class, directly Pin
H.Goli19-Sep-13 1:15
H.Goli19-Sep-13 1:15 
Hello,

I'm writing a class(MyClass) that have a subclass(Item) and a property of List of that subclass(List<item>).
MyClass have a property with name "CurrentItem" that returns required Item.
My class is like this:
C#
public class MyClass
{
    private DataTable _mainDataTable;
    private List<Item> _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<Item>();
            return _mainDataTable;
        }
        set { _mainDataTable = value; }
    }
    public List<Item> Items
    {
        get
        {
            if (_items == null && _mainDataTable != null)
            {
                _items = _mainDataTable.ConvertToListOfItems<Item>();
            }
            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];
        }
    }
}

And this code is an example of using it:
C#
Myclass obj=new Myclass();
int id=obj.CurrentItem.Id;

My problem is: I don't know that is there any way to access properties of CurrentItem directly without writing CurrentItem. like this code:
C#
Myclass obj=new Myclass();
int id=obj.Id;

Is there any way to do this?
Thanks

h.goli
AnswerRe: Accessing properties of one property of a class, directly Pin
Eddy Vluggen19-Sep-13 2:59
professionalEddy Vluggen19-Sep-13 2:59 
AnswerRe: Accessing properties of one property of a class, directly Pin
BillWoodruff19-Sep-13 3:30
professionalBillWoodruff19-Sep-13 3:30 
QuestionParse complex XML in C# Pin
Member 1026417718-Sep-13 21:45
Member 1026417718-Sep-13 21:45 
AnswerRe: Parse complex XML in C# Pin
Pete O'Hanlon18-Sep-13 22:17
mvePete O'Hanlon18-Sep-13 22:17 
GeneralRe: Parse complex XML in C# Pin
Member 1026417718-Sep-13 22:30
Member 1026417718-Sep-13 22:30 
GeneralRe: Parse complex XML in C# Pin
Pete O'Hanlon18-Sep-13 22:41
mvePete O'Hanlon18-Sep-13 22:41 
GeneralRe: Parse complex XML in C# Pin
Member 1026417718-Sep-13 23:06
Member 1026417718-Sep-13 23:06 
GeneralRe: Parse complex XML in C# Pin
Nicholas Marty18-Sep-13 23:15
professionalNicholas Marty18-Sep-13 23:15 
GeneralRe: Parse complex XML in C# Pin
Pete O'Hanlon18-Sep-13 23:29
mvePete O'Hanlon18-Sep-13 23:29 
GeneralRe: Parse complex XML in C# Pin
Member 1026417718-Sep-13 23:53
Member 1026417718-Sep-13 23:53 
GeneralRe: Parse complex XML in C# Pin
V.19-Sep-13 1:02
professionalV.19-Sep-13 1:02 
AnswerRe: Parse complex XML in C# Pin
Simon_Whale18-Sep-13 23:30
Simon_Whale18-Sep-13 23:30 
AnswerRe: Parse complex XML in C# Pin
jschell19-Sep-13 11:22
jschell19-Sep-13 11:22 
AnswerRe: Parse complex XML in C# Pin
Alan Balkany23-Sep-13 5:28
Alan Balkany23-Sep-13 5:28 
QuestionShow Multiparty Images on one form Pin
sanket16418-Sep-13 20:24
sanket16418-Sep-13 20:24 
AnswerRe: Show Multiparty Images on one form Pin
Paw Jershauge18-Sep-13 20:52
Paw Jershauge18-Sep-13 20:52 
AnswerRe: Show Multiparty Images on one form Pin
Pete O'Hanlon18-Sep-13 21:11
mvePete O'Hanlon18-Sep-13 21:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.