none
Which one has better performance, data types .NET or alias name data types C#?please Complete reading this post to end RRS feed

  • Question

  • Hi to all first of all i am sorry because my first language is not english I want understand which one has better performance C# data types or .net data types i try to understand by below code i test this code both with x86 and x64 platform.(I emphasize please Complete reading this post to end and If in doubt do not give the wrong answer and please Answer me with a document )

    StopWatch SW=new StopWatch();
       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;
           }

    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();

    in below link "said all data types are converted into .Net Data type"What does this mean?I think if this word is true so converting C# alias data types to .net data types it takes time and i tested this by above codes but i am not sure if anyone sure(not unsure I emphasize) please answer me. somebody answer there is no deference in performance but i think this is not my answer thanks a lot.link is "https://www.c-sharpcorner.com/UploadFile/dacca2/difference-between-data-type-in-C-Sharp-and-data-type-in-net/" The third paragraph.



    Thursday, February 6, 2020 6:25 PM

Answers

  • "string" is just a C# alias for System.String. Nothing is "converted". They ARE the same thing. They compile to the same instructions. There is no difference in performance.
    • Marked as answer by Reza1992 Friday, February 7, 2020 2:15 PM
    Thursday, February 6, 2020 9:08 PM
  • Hi Reza1992,

    Thank you for posting here.

    Acrym is right, they are not different.

    For example, it's like a person has a nickname. No matter what we call his real name or nickname, we are all calling the same person, and there is no difference.

    What is the difference between String and string in C#?

    Hope this coule be helpful.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Reza1992 Friday, February 7, 2020 2:14 PM
    Friday, February 7, 2020 6:20 AM

All replies

  • "string" is just a C# alias for System.String. Nothing is "converted". They ARE the same thing. They compile to the same instructions. There is no difference in performance.


    You mention a link but I don't see anything.

    Thursday, February 6, 2020 6:42 PM
  • Hi to all first of all i am sorry because my first language is not english I want understand which one has better performance C# data types or .net data types i try to understand by below code i test this code both with x86 and x64 platform.(I emphasize please Complete reading this post to end and If in doubt do not give the wrong answer and please Answer me with a document )
    StopWatch SW=new StopWatch();
       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;
           }
        }

    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();

    in below link "said all data types are converted into .Net Data type"What does this mean?I think if this word is true so converting C# alias data types to .net data types it takes time and i tested this by above codes but i am not sure if anyone sure(not unsure I emphasize) please answer me. somebody answer there is no deference in performance but i think this is not my answer thanks a lot.link is " https://www.c-sharpcorner.com/UploadFile/dacca2/difference-between-data-type-in-C-Sharp-and-data-type-in-net/" The third paragraph.


    Thursday, February 6, 2020 8:33 PM
  • "string" is just a C# alias for System.String. Nothing is "converted". They ARE the same thing. They compile to the same instructions. There is no difference in performance.
    • Marked as answer by Reza1992 Friday, February 7, 2020 2:15 PM
    Thursday, February 6, 2020 9:08 PM
  • Hi Reza1992,

    Thank you for posting here.

    Acrym is right, they are not different.

    For example, it's like a person has a nickname. No matter what we call his real name or nickname, we are all calling the same person, and there is no difference.

    What is the difference between String and string in C#?

    Hope this coule be helpful.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Reza1992 Friday, February 7, 2020 2:14 PM
    Friday, February 7, 2020 6:20 AM