I have a function (function1) in my winforms app(c#) that return an array
inside the function1
public array function1(string value)
{
string[] array = new string[12];
//assigning values to the array elements....
retrun array;
}
and i call this function like this
string id="Some id";
string[] array2 = new string[12];
array2=this.function1(id);
but it gives me error
Cannot implicitly convert type 'System.Array' to 'string[]'. An explicit conversion exists (are you missing a cast?)
please experts help me !
Change
public array function1(string value)
to
public string[] function1(string value)
And in your example of usage, you do not need to initialize your array to new string[12]
before hand, as your function returns a new array anyway.
The signature of function1 should be public string[] function1(string value)
. The return type array
doesn't match the variable of type string[]
This works, but not sure what the problem is:
public Form1()
{
InitializeComponent();
string id = "Some id";
string[] array2 = new string[12];
array2 = this.function1(id);
}
public string[] function1(string value)
{
string[] array = new string[12];
array[0] = value; // for example
return array;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.