c# - Can you make sense of this C pointer code? -
i have snippet of c code uses pointers in confusing way.
// first point specific location within array.. double* h = &h[9*i]; int line1 = 2*n*i; int line2 = line1+6; // ..and access elements using pointer, somehow.. v[line1+0]=h[0]*h[1]; v[line1+1]=h[0]*h[4] + h[3]*h[1];
what's happening here? how write equivalent in c#?
you don't write equivalent in c# because don't have pointers there (except invoking unsafe
code) - element c# array, need array ref , index, , index array.
you can, of course, same c array. convert c pointer-arithmetic c array-indexing:
int h_index = 9 * i; int line1 = 2 * n * i; int line2 = line1 + 6; v[line1 + 0] = h[h_index] * h[h_index + 1]; v[line1 + 1] = h[h_index] * h[h_index + 4] + h[h_index + 3] * h[h_index + 1];
and have can used pretty verbatim in c#.
Comments
Post a Comment