Getting an array length in C# is a trivial task. All we need to so is call the Length property of the Array Class:
int[] arr = new int[17]; int arrLength = arr.Length;
Getting an array length in C++ might be less trivial:
int arr[17]; int arrSize = sizeof(arr) / sizeof(int);
Notice that sizeof(arr) returns the array size in bytes, not its length…
Sometimes we need to know the width of a given string in pixels, do you know how to compute it? Before writing some long code, please notice that the .NET framework class library provides such a method. When Googling about this issue, we find the Graphics.MeasureString Method, here is how to use it:
Graphics graphics = this.CreateGraphics(); SizeF textSize = graphics.MeasureString("How long am I?", this.Font);
Nice isn’t it? Well, there is one little problem here, how is the Graphics object created? The written code is a Windows Forms code, so the this is the Form itself. You can’t create the Graphics object by simply allocating it because…
We pay for user submitted tutorials and articles that we publish. Anyone can send in a contribution
Learn More