locked
Get the Object Data RRS feed

  • Question

  • I need to get the cName and cType etc. public List<ConfigurationC1> C2 { get; set; } where i have public sealed class ConfigurationC1 { public string CName { get; set; } public CType cType { get; set; } } ConfigurationC1 configC1; var a=configC1.C2.CName; var b=configC1.C2.CType;

    C2.CName and C2.CType gives error

    What is the right way to get this data



    • Edited by wpf_xaml Tuesday, October 6, 2015 9:45 PM
    Tuesday, October 6, 2015 9:05 PM

Answers

  • I need to get the cName and cType etc. public List<ConfigurationC1> C2 { get; set; } where i have public sealed class ConfigurationC1 { public string CName { get; set; } public CType cType { get; set; } } ConfigurationC1 configC1; var a=configC1.C2.CName; var b=configC1.C2.CType;

    C2.CName and C2.CType gives error

    What is the right way to get this data



    Hi, you declare a ConfigurationC1 but never instanciate it.

    You dont instanciate the List, and dont add anything to the list...

    [with your classes ConfigurationC1 and CType]

     public List<ConfigurationC1> C2 { get; set; } //somwwhere in your class decalre the List
    
                ConfigurationC1 configC1 = new ConfigurationC1(); //declare and instanciate a ConfigurationC1-object
                configC1.CName = "Bla"; //set the Properties
                configC1.cType = new CType(); // { ... } set the Properties part 2
                if(C2 == null)
                    C2 = new List<ConfigurationC1>(); //instanciate the List, if its not yet instanciated
                C2.Add(configC1); //and add a ConfigurationC1 object
                var a = C2[0].CName; //get the values from the List's first entry -> index: 0, we added only one Item
                var b = C2[0].cType;

    Regards,

      Thorsten





    • Edited by Thorsten Gudera Tuesday, October 6, 2015 11:24 PM
    • Marked as answer by wpf_xaml Wednesday, October 7, 2015 2:47 AM
    Tuesday, October 6, 2015 11:00 PM