Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15136

[RESOLVED] Generic Method with BitConverter.GetBytes problem

$
0
0
I have a simple generic method.

Code:

private static byte[] GetBytes<T> (T valu)
        {
            var bytes = BitConverter.GetBytes(valu);
            if (BitConverter.IsLittleEndian)
                Array.Reverse(bytes);
            return bytes;
        }

The idea is that I can use this method with either a ushort or uint for T.
But I get the following error.

Error CS1503 Argument 1: cannot convert from 'T' to 'bool'

The error I believe is generated because one of the overloads for BitConverter.GetBytes is bool .

I just do not have a clue on how to resolve this, other than write my own method to convert a unit or ushort to bytes. Any suggestions or hints appreciated.

Viewing all articles
Browse latest Browse all 15136

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>