Answer the question
In order to leave comments, you need to log in
How to pass a property to another class?
There is a class fMain with its combo box on the form. It is necessary to transfer the data that is inside the combobox to another class. It was decided to use the property:
public string combRangesAccess
{
get
{
return combRanges.Text;
}
set
{
combRanges.Text = value;
}
}
Answer the question
In order to leave comments, you need to log in
Your combobox is a field of class fMain. Static methods do not belong to a specific object => they do not have access to the object's data. But you can pass a reference to an object as an argument to a static method.
// вот сам метод
class fMain{
//...
public static combRangesAccess(fmain ob)
{
return ob.combRanges.Text;
}
// вот Вы создаете экземпляр класса fMain
fMain obj = new fMain();
// вот вызываете метод
string text = fMain.combRangesAccess(obj);
You cannot pass anything to another class. Maybe to another object? And what prevents you from doing so - Non-
crutch options depend on your algorithm. What do you implement, how and why in this particular way. You want that at you one class (namely a class) depended on a state of a combobox? it is a bad idea. The class object is still okay - at the constructor level, you can simply pass the state of the property you need.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question