- Joined
- Sep 15, 2004
- Messages
- 190
- Reaction score
- 0
Ok guys, i've got this problem going that drives me crazy, ill try to explain the best as i can so you can understand.
The problem is, when for example i create a new class:
Then in Class1.cs i make a new instance of the object:
And then i assign some string value to it:
So now the string someName in the class customer contains the value "Michael Jackson"
Now, i create another class named Class2.cs.
And this is where i've got a problem.
How do i get the value from someName out of the instance of the object Cust created in Class1.cs into Class2.cs?
Because i would have to create an new instance of the Customer class in Class2.cs first before i can call the function:
As like above note the "new" keyword, this will create a new instance of the object, and thus someName will no longer contain "Michael Jackson".
Is there anyway to not make a new object, but rather re-use an existing one or something along those lines?
Any ideas?
Thanks for your time.
The problem is, when for example i create a new class:
Code:
class Customer
{
public string someName = "";
public void Name(string yourName)
{
someName = yourName;
}
}
Then in Class1.cs i make a new instance of the object:
Customer Cust = new Customer();
And then i assign some string value to it:
Cust.Name = "Michael Jackson";
So now the string someName in the class customer contains the value "Michael Jackson"
Now, i create another class named Class2.cs.
And this is where i've got a problem.
How do i get the value from someName out of the instance of the object Cust created in Class1.cs into Class2.cs?
Because i would have to create an new instance of the Customer class in Class2.cs first before i can call the function:
Customer Cust = new Customer();
As like above note the "new" keyword, this will create a new instance of the object, and thus someName will no longer contain "Michael Jackson".
Is there anyway to not make a new object, but rather re-use an existing one or something along those lines?
Any ideas?
Thanks for your time.
Last edited: