Search:

Type: Posts; User: Wilson_G

Search: Search took 0.01 seconds.

  1. Re: MY UDP Checksum method. How can I make it better.

    Thank you. I will take a look.
  2. Re: MY UDP Checksum method. How can I make it better.

    Well they are in truth not. There was no need to decrement indexEnd again if the length of packet byte array was odd.
    It was extra code that was not needed. It almost meant I can remove the indexEnd...
  3. Re: MY UDP Checksum method. How can I make it better.

    To answer my own question, I can probably replace this.

    int indexEnd = packet.Length -1;

    if (packet.Length%2 !=0)
    {
    indexEnd--;
    sum+= (uint)packet[^1];
    };
  4. [RESOLVED] MY UDP Checksum method. How can I make it better.

    I created this method to calculate the checksum for a UDP packet. I believe it works but I am sure it can be done a LOT better.


    static ushort GetChecksum (ref byte[] packet)
    {
    uint sum =...
  5. Re: Generic Method with BitConverter.GetBytes problem

    This place is full of great people with great advice.
    Still confused but plenty of thing to think about.
  6. Re: Generic Method with BitConverter.GetBytes problem

    Thanks KGC for that. I was halfway there to a similar solution when you posted this.
    C# is a hobby for me and this is definitely a learning experience.

    I appreciate everyones help.
  7. Re: Generic Method with BitConverter.GetBytes problem

    jmcilhinney, I appreciate you taking the time to explain what has gone wrong with my code and offering a possible solution.
    I will take another look at the code with your suggestion.

    Thanks
  8. [RESOLVED] Generic Method with BitConverter.GetBytes problem

    I have a simple generic method.


    private static byte[] GetBytes<T> (T valu)
    {
    var bytes = BitConverter.GetBytes(valu);
    if (BitConverter.IsLittleEndian)
    ...
  9. Replies
    5
    Views
    774

    Re: Ternary operation.

    si_the_greek, I did try a variant of your idea before writing the post but unfortunately it didn't work, resulting in the same error message.

    jmcilhinney, I thought it would have worked as...
  10. Replies
    5
    Views
    774

    Re: Ternary operation.

    si_the_greek, I did try a variant of your idea before writing the post but unfortunately it didn't work, resulting in the same error message.

    jmcilhinney, I thought it would have worked as...
  11. Replies
    5
    Views
    774

    Ternary operation.

    I am newish to C# and need a little help with the ternary operator.

    In the code below I would like to replace the GetProtocol method with a ternary operation.



    public...
Results 1 to 11 of 11



Click Here to Expand Forum to Full Width