Using static to Access Other Static Classes [Closed]

Asked 1 years ago, Updated 1 years ago, 73 views

Do you want to improve this question?Edit your post to clarify the issue you are trying to resolve by adding details.

Closed 6 years ago.

6 years ago

For example,

To sampleclass

public static int sample

sample=10;

Let's say that

Put this in the sample2 class

Is there a way to put the sample as static?  This is c#

c# unity3d

2022-09-30 21:02

1 Answers

Properties allow you to access sampleclass.sample directly within sample2.

class sample 2
{
    private static int sample
    {
        get
        {
            return sampleclass.sample;
        }
        set
        {
            sampleclass.sample=value;
        }
    }
}

However, it is not a true field and cannot be used as a reference.

In addition, C#6.0, using static sampleclass omits sampleclass to call the method.


2022-09-30 21:02

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.