473,383 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Function that returns an array?

Is it possible to return an array from a function? if so, how would I
go about doing so?

thank you for your help

Aug 16 '06 #1
6 58293
Hello, Th***********@gmail.com!

TRIs it possible to return an array from a function? if so, how would I
TRgo about doing so?

AFAIK you can do it via return value or via out param. I'm not mentioning ref here.

int[] array;

//returns array with 2 elements
public int[] ReturnArray()
{
return new int[] {1,2};
}

public void ReturnArray(out int[] array)
{
array = new int[] {1,2};
}
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Aug 16 '06 #2
Yes. you can get array from function.

like this

string[] GetStrs()
{
}

or

void GetStrs(out string[] strs)
{}

It's just a reference to real object.

The.Relina...@gmail.com wrote:
Is it possible to return an array from a function? if so, how would I
go about doing so?

thank you for your help
Aug 16 '06 #3
Just tell it what you want to return; two examples below.

Marc

public int[] SomeMethod() {
return new int[] {1,2,3,4,5};
}

public string[] SomeOtherMethod() {
List<stringdata = new List<string>();
data.Add("abc");
data.Add("def");
data.Add("ghi");
return data.ToArray();
}
Aug 16 '06 #4
Him

Of course, the framework is full of examples of methods that return an
array.

int[] Method(){

return new int[4];
}

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

<Th***********@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Is it possible to return an array from a function? if so, how would I
go about doing so?

thank you for your help

Aug 16 '06 #5
<Th***********@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Is it possible to return an array from a function?
Sure - why not?
Aug 16 '06 #6
Id like to thank everyone for their help, I did find a way to correct
the issue I was having.

Aug 16 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: varois83 | last post by:
Hi I am a newbie and struggling with my guestbook validation process. I have found the following function online to check the length of a form field. <?php function checkLength($string,...
2
by: BUX | last post by:
I have Function myFunction(myArgument) as string(myInteger) The line myFunction(myInteger) = myString give me an error. Also myFunction(myArgument)(myInteger) = myString give me an...
4
by: octavio | last post by:
Hello members of the comp.lang.c newsgroup. Please I need you help on the following one. Compiling the simple code I'm getting this error message. Why ? Please what's the correct type of the fb...
2
by: Tany | last post by:
How can I declare function returning array of Integer pointers . Please help !!
18
by: ben.carbery | last post by:
Hi, I have just written a simple program to get me started in C that calculates the number of days since your birthdate. One thing that confuses me about the program (even though it works) is...
7
by: lovecreatesbea... | last post by:
K&R 2, sec. 5.11 says that no need to precede function and array names with address-of operators &, why?
1
by: cyberdwarf | last post by:
Hi I wanted to return a Variant array, which contains 2 integers and a double, from my function. Public Function GroupGradeCount(GroupIdent As Integer, GradeIdent As Integer, ColNum As Integer)...
5
by: Travis | last post by:
I am using a function that returns a const char * that is usually a word, etc. How can I check to see if what it returns is empty? I tried if (function() == "") and (function() == NULL) and...
26
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure...
5
by: Immortal Nephi | last post by:
I would like to design an object using class. How can this class contain 10 member functions. Put 10 member functions into member function pointer array. One member function uses switch to call...
0
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.