Home How to access variables from other objects in C#?
Reply: 1

How to access variables from other objects in C#?

Dainis Published in 2017-11-12 16:22:22Z

As you can see, I have a number of variables setup. However, I wish to multiply the 'lengthInchConverted' and 'widthInchConverted' and output them to a textbox called 'totalAreaCM'.

I have set the methods as public, however, I cannot access the variable from the top method. How should I go about fixing this?

In the second screenshot I commented out the line of code to better illustrate my point. The 'Calculate' button will be for something else in the future.

Robert Reply to 2017-11-12 17:18:07Z

The methods may be public, but the variables are not. The variable 'lengthInchConverted' and 'widthInchConverted' are only accessible by the function they're declared in. You could declare them at the class level to make them accessible by each function in the class.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.372131 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO