Skip to main content
Tags
Link
Source Link

Access object of a class from other classes

I realise this is probably a very simple question and will be answered in no time. But wondering what to do. I have a class called Budget with an object named 'user01' I would basically like to be able to access that object across multiple classes, similar to the code below.

Main

static void Main(string[] args) { Budget user01 = new Budget(1000); } 

Budget Class

class Budget { private int _budget; public Budget(int budget) { _budget = budget; } public int UserBudget { get { return _budget; } set { _budget = value; } } } 

Expense Class

class Expenses { // What I've been trying to do... public int Something(user01.budget) { user01.budget - 100; return user01.budget; } } 

I'm not really sure where to go from here, and am hoping to a little help/explanation. Many thanks