Class With Data Structure Paramater Class C# Unity

Dennis Liu

Could someone checking for my code class if it possible to do like this, I got null inside class value. for detail check below :

classLogBarter.cs // Make a class

[System.Serializable]
public class classLogBarter {
    public string DisplayName;
    public string PlayerID;
    public int CommentID;
    public string Time;
    public List<item> ItemBarter = new List<item>(); // Here is that possible ?

    public classLogBarter (string playerid, string displayname, int commentid, string time, List<item> itembarter // Here how about this ?) {
        PlayerID = playerid;
        DisplayName = displayname;
        CommentID = commentid;
        Time = time;
        itembarter = new List<item> (); // Is this correct ?
        ItemBarter = itembarter; // Is this correct ?
    }

    public classLogBarter Clone() {
        return new classLogBarter (PlayerID, DisplayName, CommentID, Time, ItemBarter);

    }

    public classLogBarter() {

    }
}

LogBarter.cs // Add Value to the class // Asumption that BarterItem Variable Have 1 or 2 Value.

public List<classLogBarter> LogBarter = new List<classLogBarter> ();
public List<item> BarterItem = new List<item>(); // Asumption that BarterItem Have 1 or 2 Value. Here now have BarterItem[0] and BarterItem[1]

LogBarter.Add(new classLogBarter(playerID,displayNames,1,times,BarterItem));

// Debug.Log to show the LogBarter value

for (int i = 0; i < LogBarter.Count; i++) {
    for(int j = 0; j < LogBarter[i].ItemBarter.Count; j++) {
                    Debug.Log ("Player LogBarter : " + LogBarter [i].ItemBarter [j].itemName); // Here there is no value in here.

                }
}

What i want to ask is why when Debug.Log LogBarter[i].ItemBarter[j].itemName there is no item ?

Is there anything that i have miss ? or i am just do a mistake in how creating the class with paramater class ?

matiaslauriti

The error is in classLogBarter, on constructor.

You are overwriting the value that has those 2 values you are not getting:

itembarter = new List<item> (); // Is this correct ?

Remove that line and you should get the items and not null now.

You are creating a new empty List<item> but you already done that and filled it with (you said) 2 values, but when entering constructor, you are assigning a new empty one to the same variable that was holding the already filled one.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Class With Data Structure Paramater Class C# Unity

From Dev

c# pass class variable as paramater in method LINQ like?

From Dev

Class Structure and Passing Data

From Dev

What Data Structure Does the C# Class "List" Default to?

From Dev

MongoDB C# create a function that I can pass a type/class name to it as paramater

From Dev

Pass structure (or class) from C++ dll to C# (Unity 3D)

From Dev

Pass structure (or class) from C++ dll to C# (Unity 3D)

From Dev

Class designing structure in C#

From Dev

How to pass ATL com class object as paramater to COM

From Dev

Use paramater value in a custom class (Symfony2)

From Dev

group fetch / data updates (class structure design)

From Dev

Convert a nested data structure to use a class object

From Dev

Proper structure for Food class with data from json

From Dev

Check in base class if derived class' data structure contains string value

From Dev

structure as field of template class c++

From Dev

C++ - cstyle structure/class packing pertinent?

From Dev

Class to Class Data Type Conversions in C++

From Dev

How is C++'s std::set class able to implement a binary tree for ANY type of data structure?

From Dev

set data structure in C++ that contains only one appearance of each class

From Dev

Refactoring a data class in C++

From Dev

One class data use in another class data C#

From Dev

having trouble understanding an array of objects embedded within a data class structure

From Java

How to convert Class object to data structure `Map` or a `List of Maps` in Dart?

From Dev

How to parse JSON data without key names into a Java class structure?

From Dev

How to implement Java graph data-structure and class with restricted visibility?

From Dev

How to declare which member of a data structure a class operates on at construction

From Java

How to structure utility class

From Dev

Python GUI and Class Structure

From Dev

Structure of a class in Java for this example

Related Related

  1. 1

    Class With Data Structure Paramater Class C# Unity

  2. 2

    c# pass class variable as paramater in method LINQ like?

  3. 3

    Class Structure and Passing Data

  4. 4

    What Data Structure Does the C# Class "List" Default to?

  5. 5

    MongoDB C# create a function that I can pass a type/class name to it as paramater

  6. 6

    Pass structure (or class) from C++ dll to C# (Unity 3D)

  7. 7

    Pass structure (or class) from C++ dll to C# (Unity 3D)

  8. 8

    Class designing structure in C#

  9. 9

    How to pass ATL com class object as paramater to COM

  10. 10

    Use paramater value in a custom class (Symfony2)

  11. 11

    group fetch / data updates (class structure design)

  12. 12

    Convert a nested data structure to use a class object

  13. 13

    Proper structure for Food class with data from json

  14. 14

    Check in base class if derived class' data structure contains string value

  15. 15

    structure as field of template class c++

  16. 16

    C++ - cstyle structure/class packing pertinent?

  17. 17

    Class to Class Data Type Conversions in C++

  18. 18

    How is C++'s std::set class able to implement a binary tree for ANY type of data structure?

  19. 19

    set data structure in C++ that contains only one appearance of each class

  20. 20

    Refactoring a data class in C++

  21. 21

    One class data use in another class data C#

  22. 22

    having trouble understanding an array of objects embedded within a data class structure

  23. 23

    How to convert Class object to data structure `Map` or a `List of Maps` in Dart?

  24. 24

    How to parse JSON data without key names into a Java class structure?

  25. 25

    How to implement Java graph data-structure and class with restricted visibility?

  26. 26

    How to declare which member of a data structure a class operates on at construction

  27. 27

    How to structure utility class

  28. 28

    Python GUI and Class Structure

  29. 29

    Structure of a class in Java for this example

HotTag

Archive