Implicit conversion

Peter Volz 1,295 Reputation points


I've converted a C# project to VB (using a tool - I don't know C#) and my converted project has 4 warnings.

2 are warning BC42016: Implicit conversion from Long to Integer for the below 2 lines:

Source C#:
byte[] buffer = new byte[Stream.Length];
Dim buffer(Stream.Length - 1) As Byte
Source C#:
For i As Integer = 0 To Header.UIntegerNumber - 1
for (int i = 0; i < header.UIntegerNumber; i++)

2 are warning BC42016: Implicit conversion from Decimal to Long and Long to ULong for this line:

Source C#:
h = (h * 16777619) ^ buffer[i];
h = (h * 16777619) Xor buffer(i)

Source C# project does not show warnings, while converted VB shows the above 4 warnings.

How do I get rid of warnings to be able to have option strict on?

Thanks for help :)

An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,564 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 26,426 Reputation points Microsoft Vendor

    Hi @Peter Volz ,

    You can try the following code.

    Override an implicit type conversion to an explicit type transformation.

    Or choose to be compatible with more types of constructors.

            Dim buffer As Byte() = New Byte(CInt(Stream.Length) - 1) {}
            For i As Long = 0 To Header.UIntegerNumber - 1
            h = CDec((h * 16777619)) Xor buffer(i)

    Best Regards.

    Jiachen Li

    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful