Answer the question
In order to leave comments, you need to log in
How to access the properties of an object through a field class?
Good day, gentlemen.
Recently, I began to study C # tightly and the following question arose.
Let's say we have some class structure. The main class (more precisely, its object) contains data and resources that are used by other classes.
For example:
class BaseClient
{
static readonly HttpClient client = new HttpClient();
public string token { get; private set; }
public BaseClient(string token)
{
this.token = token;
}
public SecondClient SecondClient;
}
BaseClient BaseClient = new BaseClient(Token);
BaseClient.SecondClient.SomeMethod("89544511588");
Answer the question
In order to leave comments, you need to log in
Either the BaseClient fields must be static, or the SecondClient needs to somehow know about the existence of a particular BaseClient instance. For example, by passing a reference to it through the constructor.
And also naming instances in the same way as a class is a bad form.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question