Implicit conversion

Peter Volz 1,295 Reputation points
2024-03-07T05:58:17.8733333+00:00

Hello,

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];
VB:
Dim buffer(Stream.Length - 1) As Byte
Source C#:
For i As Integer = 0 To Header.UIntegerNumber - 1
VB:
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];
VB:
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 :)

VB
VB
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
    2024-03-07T08:13:37.4966667+00:00

    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
    
            Next
            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