c# - Can't access data through multiple class layers -


For my project, I have to create a data structure to represent an XML file. My Idea was to use different sections representing different sections.

My problem now is how can I change the data from the top one to the lowest layer. In my code example, three calls 2 is not a work 1. Why not work for the last time?

Is there another way to organize data?

  public class option {public string option id; Public zero setoptionID (string text) {optionID = text; }} Public class module {public option [op = op = new option [1]; Private string module id; Public Zero SetUul IDID (String Text) {moduleID = text; }} Public class listing {public module} [modul = new module [1]; Private string ShortName; Public Zero setShortName (string text) {ShortName = text; }} Public Sector List {Private Catalog [] Item = New Catalytim [1]; Public listing () {} Public Zero SatcorderListime () {items [0] .setShortName ("asdf"); // work catalogitem.modul [0] .setmoduleID ("5"); // Work Item [0] .modules [0] .setmoduleID ("5"); // does not work}}  

For me, any of the three statements does not . You have to initialize the objects themselves, not just the array.

  items [0] = new charitlight (); Item [0] .setShortName ("asdf"); Item [0]. Modul [0] = New module (); Item [0] .modul [0] .setmoduleID ("5");  

But I suggest you also use methods to add and start your classes and sub-items instead of setShortName () / setmoduleID ().

Of course this depends on the specification / your intent (which I do not know), but for example the list is a potential way of implementing the rule. You can read / write ShortName and tell all the existing modules. I take a list, an array can not add modules only one by one and you can see them before actually adding them:

  public category listimplem {Private redone list & lt ; Module & gt; MModuls; Public IEnumerable & lt; Module & gt; Models {back {MMDod; }} Public String ShortName {get; Set; } Public Catalog () {mModuls = New list & lt; Module & gt; (); } Public Zero AddModule (module module) {// Add a check that has been assigned to a module. MModuls.Add (module); }}  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -