Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Sir I have used property to transfer a function from one class to another. But no value
is coming.

What I have tried:

the way I have done it is:-
C#
class a
{
    public string [,,,] allcontrols() {...function body...}
    public string[,,,] hh => allcontrols();
}
when this is called in another class no value is shown
this way it is called :-
C#
class b
{
  a cc = new a();
  string[,,,] nn = new string[1,2,3,4];
  nn = cc.hh;
  var str = nn.GetValue(0,1,0,0).ToString()
  MessageBox.Show(str);
}
no value is shown

what to do?
Posted
Updated 3-Feb-21 6:32am
v4

1 solution

For a start, you cannot have code directly inside a class. Your class B code block is missing a function, and will not compile as-is.

Secondly, there's no point creating a new array only to throw it away on the next line:
C#
string[,,,] nn = new string[1,2,3,4]; // Create a new array...
nn = cc.hh; // ... and throw it away.
Remove the new string[1,2,3,4]:
C#
string[,,,] nn;
nn = cc.hh;
You can even join the two lines together:
C#
string[,,,] nn = cc.hh;


Finally, we have no idea what your allcontrols method is returning. If you're getting an exception, then it's likely that the method is not returning an array with the expected number of dimensions. If you're getting a blank message box, then the method is returning an array which contains no values.

You need to debug your code to find out what's happening. We can't do that for you.
 
Share this answer
 
Comments
Member 12712527 4-Feb-21 2:40am    
the function 'allcontrols' is returning a string array. simple only by seeing the return
type.
the value of this array is seen in the messagebox function, called from another function of the same class but value is missing once called from another class.
why...? does my calling of a function whose return type is a string array is wrong...?
please tell how to return that function from one class to another without loosing the values...
Richard Deeming 4-Feb-21 3:36am    
The return value will not be changed by the code you've shown. But it could change depending on what the code from your allcontrols method is doing, which we can't see.

Debug your code. We can't do that for you.
Member 12712527 4-Feb-21 4:01am    
sir in the class where allcontrols() is declared the values are seen but from different function no value is seen once called by another class .the allcontrols() function is receiving data in the array used in it and returning back that array in the return type of the function ....
Richard Deeming 4-Feb-21 4:03am    
Once again, we cannot see what your function is doing. We cannot debug your code for you. YOU need to debug your code.

At a random guess, you're comparing the values returned by different instances of your class - the code in class b creates a new instance of class a.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900