❔ Offset property for array
Suppose I have an array:
public int[,] paddedArray = new int[width + 6, height + 6];
I want to make a property that accesses values offset, to get something like
unpaddedArray[x,y]: get gives paddedArray[x+3,y+3], and set will set paddedArray[x+3,y+3];
Would anyone know how to define this?
4 Replies
I would like to do this in a really lightweight way, because the alternative is just to put a const everywhere, and that would just be obnoxious
I could do something like :
But I'd like to know if there is a simpler way to make the syntax more like just accessing the array itself.
You can use indexers to make something like this
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/indexers/using-indexers
Using Indexers - C# Programming Guide
Learn how to declare and use an indexer for a class, struct, or interface in C#. This article includes example code.
thank you. that is useful
I tried to avoid a custom mini class, but I think it is worth it
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.