How to performs explicit casting from int to uint, short, ushort and ulong in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = 100009;

            uint ui = (uint)n;
            Console.WriteLine(ui);

            short s = (short)n;
            Console.WriteLine(s);

            ushort us = (ushort)n;
            Console.WriteLine(us);

            ulong ul = (ulong)n;
            Console.WriteLine(ul);
        }
    }
}

/*
run:
  
100009
-31063
34473
100009

*/

 



answered Jan 12, 2017 by avibootz

Related questions

1 answer 174 views
174 views asked Feb 5, 2021 by avibootz
1 answer 346 views
346 views asked Feb 10, 2021 by avibootz
1 answer 177 views
1 answer 148 views
1 answer 160 views
1 answer 157 views
157 views asked Jan 13, 2017 by avibootz
...