When I pass an array as a function parameter, it yields the following
compile error. Any ideas?? However, if I create a variable that holds an
array, and pass that variable to the function parameter, then it's working
fine. Any ideas?? Thanks!
public static int[] getFreq(string[] s)
{...
}
int[] res = getFreq({"eee", "ewsww"});
WordFreq.cs(7,23): error CS1525: Invalid expression term '{'
WordFreq.cs(7,24): error CS1026: ) expected
WordFreq.cs(7,29): error CS1002: ; expected
WordFreq.cs(7,29): error CS1525: Invalid expression term ','
WordFreq.cs(7,31): error CS1002: ; expected
WordFreq.cs(7,38): error CS1002: ; expected
WordFreq.cs(7,39): error CS1525: Invalid expression term ')' 2 4548
Matthew,
You need to declare the array. Arrays are managed objects in .NET, so
that needs to be reflected somewhere. If you change your code to this:
int[] res = getFreq(new string[]{"eee", "ewsww"});
Then it will work.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Matthew Louden" <jr********@hotmail.com> wrote in message
news:ef**************@tk2msftngp13.phx.gbl... When I pass an array as a function parameter, it yields the following compile error. Any ideas?? However, if I create a variable that holds an array, and pass that variable to the function parameter, then it's working fine. Any ideas?? Thanks!
public static int[] getFreq(string[] s) {... }
int[] res = getFreq({"eee", "ewsww"});
WordFreq.cs(7,23): error CS1525: Invalid expression term '{' WordFreq.cs(7,24): error CS1026: ) expected WordFreq.cs(7,29): error CS1002: ; expected WordFreq.cs(7,29): error CS1525: Invalid expression term ',' WordFreq.cs(7,31): error CS1002: ; expected WordFreq.cs(7,38): error CS1002: ; expected WordFreq.cs(7,39): error CS1525: Invalid expression term ')'
"Matthew Louden" wrote... When I pass an array as a function parameter, it yields the following compile error. Any ideas??
public static int[] getFreq(string[] s) {... }
int[] res = getFreq({"eee", "ewsww"});
You're trying to send a "list of strings", while the method takes an
array-object as parameter. You have to initialize the array-object itself as
well:
int[] res = getFreq( new string[]{"eee", "ewsww"} );
// Bjorn A This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: ritchie |
last post by:
Hi all,
I am new to this group and I have question that you may be able to
help me with.
I am trying to learn C but am currently stuck on this.
First of all, I have a function for each sort...
|
by: wilson |
last post by:
Dear all,
In this time, I want to pass array to function.
What should I declare the parameter in the function?i
int array or int array? Which one is correct?
...
|
by: nospam |
last post by:
Hello!
I can pass a "pointer to a double" to a function that accepts
double*, like this:
int func(double* var) {
*var=1.0;
...
}
|
by: Alan Silver |
last post by:
Hello,
I'm a bit surprised at the amount of boilerplate code required to do
standard data access in .NET and was looking for a way to improve
matters. In Classic ASP, I used to have a common...
|
by: _Mario.lat |
last post by:
Hallo,
I have a little question:
In the function session_set_save_handler I can pass the name of function
which deal with session.
In Xoops code I see the use of this function like that:
...
|
by: Abhi |
last post by:
I wrote a function foo(int arr) and its prototype
is declared as foo(int arr); I modify the values of the array in the
function and the values are getting modified in the main array which
is...
|
by: =?Utf-8?B?V2hpdG5leSBLZXc=?= |
last post by:
Hi there,
I'm having a bit of trouble using an HRASCONN object as a class member
variable inside my managed C++ class. When I call RasDial() and pass in the
address of my HRASCONN object, I get...
|
by: QQ |
last post by:
I have one integer array
int A;
I need to pass this array into a function and evaluate this array in
this function
how should I pass?
Is it fine?
void test(int *a)
|
by: SM |
last post by:
Hello,
Such a simple question and i can't find the answer(see code below).
Here it is:
I have a function: ini()
In that function, i call a function (load_CDThumbnail) that creates an
array and...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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,...
| |