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.GetLowerB ound(0); i <= arrRv.GetUpperB ound(0); i++ ){
for ( int j = arrRv.GetLowerB ound(1); j <= arrRv.GetUpperB ound(1); j++ )
{
...
...
...
}
}
arrRv.SetValue( strAnswer, i, j );
return arrRv;
}
TIA.
regards,
Andrew 6 51510
did you try string[,] ?
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Andrew" <An****@discuss ions.microsoft. com> wrote in message
news:A5******** *************** ***********@mic rosoft.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.GetLowerB ound(0); i <= arrRv.GetUpperB ound(0); i++ ){ for ( int j = arrRv.GetLowerB ound(1); j <= arrRv.GetUpperB ound(1); j++ ) { ... ... ... } } arrRv.SetValue( strAnswer, i, j ); return arrRv; }
TIA.
regards, Andrew
Hi,
Hope the following will answer your question
private void button1_Click(o bject 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****@discuss ions.microsoft. com> wrote in message
news:A5******** *************** ***********@mic rosoft.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.GetLowerB ound(0); i <= arrRv.GetUpperB ound(0); i++ ){ for ( int j = arrRv.GetLowerB ound(1); j <= arrRv.GetUpperB ound(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 Multidimensiona l
array from a function...
private void button1_Click(o bject 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****@discuss ions.microsoft. com> wrote in message
news:A5******** *************** ***********@mic rosoft.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.GetLowerB ound(0); i <= arrRv.GetUpperB ound(0); i++ ){ for ( int j = arrRv.GetLowerB ound(1); j <= arrRv.GetUpperB ound(1); j++ ) { ... ... ... } } arrRv.SetValue( strAnswer, i, j ); return arrRv; }
TIA.
regards, Andrew
Andrew <An****@discuss ions.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.GetLowerB ound(0); i <= arrRv.GetUpperB ound(0); i++ ){ for ( int j = arrRv.GetLowerB ound(1); j <= arrRv.GetUpperB ound(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.co m> 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 multidimensiona l 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 Multidimensiona l array from a function...
private void button1_Click(o bject 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****@discuss ions.microsoft. com> wrote in message news:A5******** *************** ***********@mic rosoft.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.GetLowerB ound(0); i <= arrRv.GetUpperB ound(0); i++ ){ for ( int j = arrRv.GetLowerB ound(1); j <= arrRv.GetUpperB ound(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 multidimensiona l array. You should search for "jagged array"
and "rectangula r array" for more details.
Also I have since decided not to use a multidimensiona l 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 but if i do then they
don't change in the action listener. any suggestions on how to make this
work?
public String drawLoginPopUp( )
{
|
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,
'b_id' => 9,
'c_id' => 3,
|
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 interger, byval j as integer) as myclas
dim obj(20) as myclas
obj(0).additem( i,j
obj(1).additem(i,j
| |
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. Dim ptColor As Color
4. End Structure
|
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 application but I get a type
mismatch.
I know the array is being returned because I can get the Ubound of the
array but when I try and print out the items int he array it throws an
error. Is there something that I need to do to pass this array back/
|
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. Here is
what I have:
<?
// create a new curl resource
$ch = curl_init();
// set URL and other appropriate options
|
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 C# to a function exported by the DLL.
Moreover, I have following struct (in C# and C++, as well):
struct myStruct {
unsigned int val1;
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |