-3

Hi to all first of all i am sorry because my first language is not english I want understand which one is faster C# data types or .net data types i try to understand by below code and i think .net data types is faster(is this correct?) i test this code both with x86 and x64 platform

            SW.Start();
            for (Int32 i = 0; i < 99999; i++)
            {
                for (Int32 j = 0; j < 999; j++)
                {
                    Int32 a = 37;
                    Int32 b = 37;
                    Double c = Math.Pow(a, b);
                    String d = "abcde";
                    String e = "abcde";
                    String f = d + e;
                }


            }
            Console.WriteLine(SW.Elapsed.TotalMilliseconds);
            SW.Stop();
            Console.ReadKey();

and my second code


  Stopwatch SW = new Stopwatch();
            SW.Start();
            for (int i = 0; i < 99999; i++)
            {
                for (int j = 0; j < 999; j++)
                {
                    int a = 37;
                    int b = 37;
                    double c = Math.Pow(a, b);
                    string d = "abcde";
                    string e = "abcde";
                    string f = d + e;
                }


            }
            Console.WriteLine(SW.Elapsed.TotalMilliseconds);
            SW.Stop();
            Console.ReadKey();

thank a lot

Reza
  • 1
  • 4
  • 9
    C# is a .NET language. There is no such thing as a "C# type" vs. a ".NET type"; all C# types are .NET types as well. `Stopwatch` is useless for benchmarking very short-running code like this; use something like [BenchmarkDotNet](https://benchmarkdotnet.org/) instead. This should prove that there is no difference in the posted code snippets, because `int` and `Int32` are the same type (as are `double` and `Double`, `string` and `String` etc.) – Jeroen Mostert Feb 06 '20 at 13:33
  • `int` is syntax sugar for `System.Int32` – Magnetron Feb 06 '20 at 13:35
  • Yeah. You could rip out all those types - actually I do that using EditorConfig, they get flagged as warnings and I get a fast action to convert them to system types. No idea why they even did put them in. – TomTom Feb 06 '20 at 13:36

1 Answers1

0

int is an alias for Int32. long for Int64.

enter image description here

kara
  • 2,942
  • 4
  • 16
  • 29