Pointing to array element

Posted by regular on Stack Overflow See other posts from Stack Overflow or by regular
Published on 2012-12-17T17:00:36Z Indexed on 2012/12/17 17:03 UTC
Read the original article Hit count: 222

Filed under:
|
|

What I'm trying to achieve is say i have an array, i want to be able to modify a specific array element throughout my code, by pointing at it.

for example in C++ i can do this

int main(){
 int arr [5]= {1,2,3,4,5};
 int *c = &arr[3];
 cout << arr[3] <<endl;
 *c = 0;
 cout << arr[3]<<endl;
}

I did some googling and there seems to be a way to do it through 'unsafe', but i don't really want to go that route.

I guess i could create a variable to store the indexes, but I'm actually dealing with slightly more complexity (a list within a list. so having two index variables seems to add complexity to the code.)

C# has a databinding class, so what I'm currently doing is binding the array element to a textbox (that i have hidden) and modifying that textbox whenever i want to modify the specific array element, but that's also not a good solution (since i have a textbox that's not being used for its intended purpose - a bit misleading).

© Stack Overflow or respective owner

Related posts about c#

Related posts about arrays