N
N
Nikita072019-01-30 12:02:05
.NET
Nikita07, 2019-01-30 12:02:05

How to work with class variables?

Good afternoon, the question arose, how to work with class variables?
Let's say we have this code:

using System;
class A
{
    private int Variant;
    public int Pr {
      set { Variant = value; }
      get { return Variant; } }
class B
{
     private A Varaint2;
}

how it is possible to work with variable Varaint2? Let's say how to initialize it, with what?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Gaydak, 2019-01-30
@Nikita07

Em. just read about class constructors. everything should become clear.
find out that there is a default
one and you can create
Varaint2 = new A();
and many other useful things))
Update.
just in case, I’ll add it. suddenly ...
just for understanding, it would be nice to learn that classes are just a description / structure / classification)) I don’t know how to call it more correctly.
you work with class objects. create an instance of a class (a link to it), or get a link to an existing one.
And already at the link, fields, methods, etc. are available to you.))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question