Is there any way can C# pass an array in function like C++?
In C++, we can pass the array plus offset and length very neat like below
void myFunction(int A[], int m) // m is length of A
{
myFunction2(A+1, m - 1);
}
Can C# do it too?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Sure. However you can’t modify pointers, so you would need to pass the offset separately. Also, you don’t need to pass around the length, because all C# Arrays have a
.Lengthproperty to get the array size.