0

I have the following code in C# below:

short* gArray = stackalloc short[3 * 256];

would like the equivalent in VB.net

I tried to do the conversion, with some different online tools, but it only returns me as a type of Invalid Syntax and / or does not exist for the VB.net syntax structure.

If it is possible to chat between syntaxes, as I do in a simplified way (any other types of code, such as Integers, Booleans, among others)


This is the complete code used in C#

public static unsafe bool SetBrightness(int brightnessValue)
{
    if (brightnessValue > 255)
        brightnessValue = 255;
    if (brightnessValue < 0)
        brightnessValue = 0;
    short* gArray = stackalloc short[3 * 256];
    short* idx = gArray;
    for (int j = 0; j < 3; j++)
    {
        for (int i = 0; i < 256; i++)
        {
            int arrayVal = i * (brightnessValue + 128);
            if (arrayVal > 65535)
                arrayVal = 65535;
            *idx = (short)arrayVal;
            idx++;
        }
    }
}
14
  • 3
    That's unsafe code. There is no such thing in VB.NET. Commented Mar 9, 2021 at 18:40
  • 2
    Does this answer your question? How can I use unsafe code in VB.Net? Commented Mar 9, 2021 at 18:43
  • There is some alternative, at least reading this social.msdn.microsoft.com/Forums/en-US/… but if it works for you probably depends on your exact context Commented Mar 9, 2021 at 18:44
  • In general, you shouldn't care about where memory is allocated, either in C# or VB.NET. Unsafe code in C# only exists for very specific use cases. Commented Mar 9, 2021 at 18:47
  • I updated my question by inserting the context code using it in my application, so that you can better understand what I want ... only if conversion is possible or not, use the same function as C# in VB.net Commented Mar 9, 2021 at 19:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.