/// <summary>
/// Returns an array of all ArtworkData filtered by User ID
/// </summary>
/// <param name="UsersID">User ID to filter on</param>
/// <returns></returns>
public static Array[] GetDataRecords(int UsersID)
{
ArtworkData[] Labels;
Labels = new ArtworkData[3];
return Labels[];
}
I get a syntax error, ;
expected after return Labels[]
.
Am I doing this right?
This question is related to
c#
asp.net
arrays
return-value
public static ArtworkData[] GetDataRecords(int UsersID)
{
ArtworkData[] Labels;
Labels = new ArtworkData[3];
return Labels;
}
This should work.
You only use the brackets when creating an array or accessing an array. Also, Array[]
is returning an array of array. You need to return the typed array ArtworkData[]
.
Two changes are needed:
Array[]
to ArtWorkData[]
Labels[]
in the return statement to Labels
You should return the variable withouth the brackets
Return Labels
return Labels;
should do the trick!
public static ArtworkData[] GetDataRecords(int UsersID)
{
ArtworkData[] Labels;
Labels = new ArtworkData[3];
return Labels;
}
static void Main()
{
for (int i=0; i<GetNames().Length; i++)
{
Console.WriteLine (GetNames()[i]);
}
}
static string[] GetNames()
{
string[] ret = {"Answer", "by", "Anonymous", "Pakistani"};
return ret;
}
Source: Stackoverflow.com