MrDysprosium MrDysprosium - 1 year ago 150
C# Question

How do I use a variable outside of a partial class?

I'm new to C#, and I'm new to the idea of "partial" classes.

I wish to access the "grid" variable outside of this "MainWindow" class. How would I go about doing that?

enter image description here

Answer Source

Partial means that your class is split among different files, it has nothing to do with the exposure of variables to other classes.

Your grid is a local variable in your current method, so it's not accessible by others. If you want to make it accessible, define it as a property instead.

public DataGrid Grid { get; set; }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download