H
Helmut Giese
Hello out there,
I am passing a string[] to a form's constructor, it gets displayed in
a ListBox, the user can change it and in the end I want it back.
I have a solution I don't particularly like and thought about using a
'ref' parameter. Inside a function I can use it to 'pass back' data -
but in this scenario the 'passing back' will have to happen later. So
I thought I could declare a (normal) variable to be a 'ref' - but the
compiler doesn't like it.
// class variables
ref string[] strLstFromCaller; // compiler error
Form(ref string[] strLst) {
// save the reference to strLst "somehow"
strLstFromCaller = strLst;
}
btnClose_Click(...) {
// get the (possibly changed) ListBox's content
...
// and return it to the caller via strLstFromCaller
}
In C or C++ (where I come from) one would just use a pointer and go on
but here I wonder: How could I achieve what I want in C#?
Any insight wll be greatly appreciated.
Best regards
Helmut Giese
I am passing a string[] to a form's constructor, it gets displayed in
a ListBox, the user can change it and in the end I want it back.
I have a solution I don't particularly like and thought about using a
'ref' parameter. Inside a function I can use it to 'pass back' data -
but in this scenario the 'passing back' will have to happen later. So
I thought I could declare a (normal) variable to be a 'ref' - but the
compiler doesn't like it.
// class variables
ref string[] strLstFromCaller; // compiler error
Form(ref string[] strLst) {
// save the reference to strLst "somehow"
strLstFromCaller = strLst;
}
btnClose_Click(...) {
// get the (possibly changed) ListBox's content
...
// and return it to the caller via strLstFromCaller
}
In C or C++ (where I come from) one would just use a pointer and go on
but here I wonder: How could I achieve what I want in C#?
Any insight wll be greatly appreciated.
Best regards
Helmut Giese