Hi all,
I have a method that wants to return an array. What datatype should I use ?
I tried using an "Array" but there was a compilation error. Why ?
public Array setReviewAll2 (int intNumQn)
int rows = intNumQn;
int cols = 3;
string [,] arrRv = new string [rows,cols];
for ( int i = arrRv.GetLowerBound(0); i <= arrRv.GetUpperBound(0); i++ ){
for ( int j = arrRv.GetLowerBound(1); j <= arrRv.GetUpperBound(1); j++ )
{
...
...
...
}
}
arrRv.SetValue( strAnswer, i, j );
return arrRv;
}
TIA.
regards,
Andrew 6 51486
did you try string[,] ?
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Andrew" <An****@discussions.microsoft.com> wrote in message
news:A5**********************************@microsof t.com... Hi all,
I have a method that wants to return an array. What datatype should I use ? I tried using an "Array" but there was a compilation error. Why ?
public Array setReviewAll2 (int intNumQn) int rows = intNumQn; int cols = 3; string [,] arrRv = new string [rows,cols]; for ( int i = arrRv.GetLowerBound(0); i <= arrRv.GetUpperBound(0); i++ ){ for ( int j = arrRv.GetLowerBound(1); j <= arrRv.GetUpperBound(1); j++ ) { ... ... ... } } arrRv.SetValue( strAnswer, i, j ); return arrRv; }
TIA.
regards, Andrew
Hi,
Hope the following will answer your question
private void button1_Click(object sender, EventArgs e)
{
string[] b=tes();
// Out put hi hello
MessageBox.Show(b[0].ToString() + ' ' + b[1].ToString() ) ;
}
private string[] tes()
{
string[] a = new string[2];
a[0] = "hi";
a[1] = "hello";
return a;
}
Vinu
"Andrew" <An****@discussions.microsoft.com> wrote in message
news:A5**********************************@microsof t.com... Hi all,
I have a method that wants to return an array. What datatype should I use ? I tried using an "Array" but there was a compilation error. Why ?
public Array setReviewAll2 (int intNumQn) int rows = intNumQn; int cols = 3; string [,] arrRv = new string [rows,cols]; for ( int i = arrRv.GetLowerBound(0); i <= arrRv.GetUpperBound(0); i++ ){ for ( int j = arrRv.GetLowerBound(1); j <= arrRv.GetUpperBound(1); j++ ) { ... ... ... } } arrRv.SetValue( strAnswer, i, j ); return arrRv; }
TIA.
regards, Andrew
Hi,
Hope this might be use full... this is how to return a Multidimensional
array from a function...
private void button1_Click(object sender, EventArgs e)
{
string[,] b=tes();
MessageBox.Show(b[1,1].ToString());
}
private string[,] tes()
{
string[,] siblings = new string[2, 2] { { "Mike", "Amy" }, {
"Mary", "Albert" } };
return siblings;
}
Vinu
"Andrew" <An****@discussions.microsoft.com> wrote in message
news:A5**********************************@microsof t.com... Hi all,
I have a method that wants to return an array. What datatype should I use ? I tried using an "Array" but there was a compilation error. Why ?
public Array setReviewAll2 (int intNumQn) int rows = intNumQn; int cols = 3; string [,] arrRv = new string [rows,cols]; for ( int i = arrRv.GetLowerBound(0); i <= arrRv.GetUpperBound(0); i++ ){ for ( int j = arrRv.GetLowerBound(1); j <= arrRv.GetUpperBound(1); j++ ) { ... ... ... } } arrRv.SetValue( strAnswer, i, j ); return arrRv; }
TIA.
regards, Andrew
Andrew <An****@discussions.microsoft.com> wrote: I have a method that wants to return an array. What datatype should I use ? I tried using an "Array" but there was a compilation error. Why ?
public Array setReviewAll2 (int intNumQn) int rows = intNumQn; int cols = 3; string [,] arrRv = new string [rows,cols]; for ( int i = arrRv.GetLowerBound(0); i <= arrRv.GetUpperBound(0); i++ ){ for ( int j = arrRv.GetLowerBound(1); j <= arrRv.GetUpperBound(1); j++ ) { ... ... ... } } arrRv.SetValue( strAnswer, i, j ); return arrRv; }
Your compilation error is due to you using i and j outside the loop, I
suspect.
Note that as you know the lower and upper bounds anyway, and because C#
knows the type of arrRv to be string[,] you can make your code a lot
simpler:
for (int i=0; i < rows; i++)
{
for (int j=0; j < cols; j++)
{
arrRv[i,j] = ...;
}
}
A string[,] return type would generally be preferable though.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Hi guys,
Thanks for your replies. Yup, string [,] works fine.
I was wondering if there is a difference between string[][] and string[,] ??
Also I have since decided not to use a multidimensional array in this
instance coz webservices dun support multi-dimensional arrays.
regards,
andrew
"vinu" wrote: Hi,
Hope this might be use full... this is how to return a Multidimensional array from a function...
private void button1_Click(object sender, EventArgs e) {
string[,] b=tes(); MessageBox.Show(b[1,1].ToString());
}
private string[,] tes() { string[,] siblings = new string[2, 2] { { "Mike", "Amy" }, { "Mary", "Albert" } }; return siblings; }
Vinu "Andrew" <An****@discussions.microsoft.com> wrote in message news:A5**********************************@microsof t.com... Hi all,
I have a method that wants to return an array. What datatype should I use ? I tried using an "Array" but there was a compilation error. Why ?
public Array setReviewAll2 (int intNumQn) int rows = intNumQn; int cols = 3; string [,] arrRv = new string [rows,cols]; for ( int i = arrRv.GetLowerBound(0); i <= arrRv.GetUpperBound(0); i++ ){ for ( int j = arrRv.GetLowerBound(1); j <= arrRv.GetUpperBound(1); j++ ) { ... ... ... } } arrRv.SetValue( strAnswer, i, j ); return arrRv; }
TIA.
regards, Andrew
Andrew wrote: Thanks for your replies. Yup, string [,] works fine. I was wondering if there is a difference between string[][] and string[,] ??
Yes - string[][] is an array of arrays of strings, and a string[,] is a
genuine multidimensional array. You should search for "jagged array"
and "rectangular array" for more details.
Also I have since decided not to use a multidimensional array in this instance coz webservices dun support multi-dimensional arrays.
I don't know the details of that, but I wouldn't be surprised.
Jon This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: the gullers |
last post by:
I am trying to return an array of strings (basicaly the contents of the
textfield) to the main class... when i put this piece of code it tells me
that i need to declare the array of strings final...
|
by: Marc van Boven |
last post by:
I'm stuck with the following problem:
My nusoap-client calls a server-function giveCombination(). The
function giveCombination should return something like
array(
=> array(
'a_id' => 6,...
|
by: priya |
last post by:
Hi all,
I am new to this group.I am working in c language.I have dount
in pointer? how to retun array of pointer in function?
example
main()
|
by: kathy |
last post by:
how to return array from function?
|
by: Ali |
last post by:
hi i need to send some data to the function and want to return array of object bac
lik
dim obj() as myclass=AddIt(i,j
i dont know that is write syntax or no
public function addit(byval i as...
|
by: Sam |
last post by:
Hi All
I have couple of question regarding property of a class and structures.
**** ---- Here is my class and structure ---- *****
1. Public Structure MyPoint
2. Dim p As Point
3. ...
|
by: anthony |
last post by:
I have a dataset filling an array from the database
Dim ds As DataSet = New DataSet
da.Fill(ds, "table")
returnResults = ds.Tables("table").Select
I want to return the array to the asp...
|
by: Raj |
last post by:
I need a VB function to return array of collections like
Private Type Employee
empname as string
address as string
salary as integer
deptno as integer
End Type
dim employees() as Employee
|
by: Igoogler |
last post by:
I am currently trying to return an array from curl and it doesn't seem
to be working. What I basically want it to is to search the remote
page for some text and then perform and If Then statement. ...
|
by: =?Utf-8?B?RGFya3Jpc2Vy?= |
last post by:
Mates,
the problem is pretty simple, but I'm unable to manage it... Therefore
asking you for help.
Situation:
Have managed code in C# and unamanged code in C++ DLL.
I need to make a call from...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |