C
C#2y ago
Luna

❔ Getting a value from an class in a list that is an attribute from another class

This code is an exmaple
class a{
.............
public List<b> listB { get; set; }
.............
}

public class b{
public int number { get; set; }
public string text { get; set; }
}
class a{
.............
public List<b> listB { get; set; }
.............
}

public class b{
public int number { get; set; }
public string text { get; set; }
}
I have an instance of class a, and I want to get the string text from 1 of the objects in the list List<b> listB how can I do that? I'm new to OOP and making this project to get better
5 Replies
Thinker
Thinker2y ago
yourAObject.listB[index].text
Angius
Angius2y ago
(also, it's not an attribute but a property) $structure
MODiX
MODiX2y ago
namespace Namespace;

[Attribute]
public class Class
{
public string PublicField;
private bool _privateField;
protected double protectedField;

public int PublicProperty { get; set; }

public Class() {} // Constructor

public void Method(int parameter)
{
var localVariable = parameter;
}
}
namespace Namespace;

[Attribute]
public class Class
{
public string PublicField;
private bool _privateField;
protected double protectedField;

public int PublicProperty { get; set; }

public Class() {} // Constructor

public void Method(int parameter)
{
var localVariable = parameter;
}
}
For C# versions older than 10, see $StructureOld
Angius
Angius2y ago
Knowing proper nomenclature helps search for answers faster
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server