<p>In C#, <code>int</code> and <code>Int32</code> are the same thing, but I've read a number of times that <code>int</code> is preferred over <code>Int32</code> with no reason given. Is there a reason, and should I care?</p>

[{'answer_id': 62538, 'author': 'David Basarab', 'author_id': 2469, 'author_profile': 'https://Stackoverflow.com/users/2469', 'pm_score': 2, 'selected': False, 'text': "<p>You should not care.  If size is a concern I would use byte, short, int, then long.  The only reason you would use an int larger than int32 is if you need a number higher than 2147483647 or lower than -2147483648.</p>\n\n<p>Other than that I wouldn't care, there are plenty of other items to be concerned with.</p>\n"}, {'answer_id': 62552, 'author': 'Raithlin', 'author_id': 6528, 'author_profile': 'https://Stackoverflow.com/users/6528', 'pm_score': 3, 'selected': False, 'text': "<p>I know that the best practice is to use int, and all MSDN code uses int. However, there's not a reason beyond standardisation and consistency as far as I know.</p>\n"}, {'answer_id': 62555, 'author': 'James Sutherland', 'author_id': 6779, 'author_profile': 'https://Stackoverflow.com/users/6779', 'pm_score': 8, 'selected': False, 'text': "<p>The two are indeed synonymous; <code>int</code> will be a little more familiar looking, <code>Int32</code> makes the 32-bitness more explicit to those reading your code. I would be inclined to use <code>int</code> where I just need 'an integer', <code>Int32</code> where the size is important (cryptographic code, structures) so future maintainers will know it's safe to enlarge an <code>int</code> if appropriate, but should take care changing <code>Int32</code>s in the same way.</p>\n\n<p>The resulting code will be identical: the difference is purely one of readability or code appearance.</p>\n"}, {'answer_id': 62557, 'author': 'Simon Steele', 'author_id': 4591, 'author_profile': 'https://Stackoverflow.com/users/4591', 'pm_score': 3, 'selected': False, 'text': '<p>There is no difference between <code>int</code> and <code>Int32</code>, but as <code>int</code> is a language keyword many people prefer it stylistically (just as with <code>string</code> vs <code>String</code>).</p>\n'}, {'answer_id': 62558, 'author': 'Jesper Kihlberg', 'author_id': 6976, 'author_profile': 'https://Stackoverflow.com/users/6976', 'pm_score': 2, 'selected': False, 'text': '<p><code>int</code> and <code>Int32</code> is the same. <code>int</code> is an alias for <code>Int32</code>.</p>\n'}, {'answer_id': 62575, 'author': 'Greg D', 'author_id': 6932, 'author_profile': 'https://Stackoverflow.com/users/6932', 'pm_score': 3, 'selected': False, 'text': "<p>In my experience it's been a convention thing.  I'm not aware of any technical reason to use int over Int32, but it's:</p>\n\n<ol>\n<li>Quicker to type.</li>\n<li>More familiar to the typical C# developer.</li>\n<li>A different color in the default visual studio syntax highlighting.</li>\n</ol>\n\n<p>I'm especially fond of that last one.  :)</p>\n"}, {'answer_id': 62585, 'author': 'spoulson', 'author_id': 3347, 'author_profile': 'https://Stackoverflow.com/users/3347', 'pm_score': 4, 'selected': False, 'text': '<p>As already stated, <code>int</code> = <code>Int32</code>.  To be safe, be sure to always use <code>int.MinValue</code>/<code>int.MaxValue</code> when implementing anything that cares about the data type boundaries.  Suppose .NET decided that <code>int</code> would now be <code>Int64</code>, your code would be less dependent on the bounds.</p>\n'}, {'answer_id': 62600, 'author': 'Jack Bolding', 'author_id': 5882, 'author_profile': 'https://Stackoverflow.com/users/5882', 'pm_score': 2, 'selected': False, 'text': '<p>int is the same as System.Int32 and when compiled it will turn into the same thing in <a href="http://en.wikipedia.org/wiki/Common_Intermediate_Language" rel="nofollow noreferrer">CIL</a>.  </p>\n\n<p>We use int by convention in C# since C# wants to look like C and C++ (and Java) and that is what we use there...</p>\n\n<p>BTW, I do end up using System.Int32 when declaring imports of various Windows API functions. I am not sure if this is a defined convention or not, but it reminds me that I am going to an external DLL...</p>\n'}, {'answer_id': 62604, 'author': 'RobbieGee', 'author_id': 6752, 'author_profile': 'https://Stackoverflow.com/users/6752', 'pm_score': -1, 'selected': False, 'text': "<p>The bytes int can hold depends on what you compiled it for, so when you compile your program for 32 bit processors, it holds numbers from 2^32/2 to -2^32/2+1, while compiled for 64 bit it can hold from 2^64/2 to -2^64/2+1. int32 will always hold 2^32 values.</p>\n\n<p><strong>Edit</strong> : Ignore my answer, I didn't see C#. My answer was intended for C and C++. I've never used C#</p>\n"}, {'answer_id': 62612, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>It makes no difference in practice and in time you will adopt your own convention.  I tend to use the keyword when assigning a type, and the class version when using static methods and such:</p>\n\n<pre><code>int total = Int32.Parse("1009");\n</code></pre>\n'}, {'answer_id': 62616, 'author': 'Stacker', 'author_id': 6574, 'author_profile': 'https://Stackoverflow.com/users/6574', 'pm_score': 0, 'selected': False, 'text': "<p>You should not care in most programming languages, unless you need to write very specific mathematical functions, or code optimized for one specific architecture... Just make sure the size of the type is enough for you (use something bigger than an Int if you <strong>know</strong> you'll need more than 32-bits for example)</p>\n"}, {'answer_id': 62630, 'author': 'Brownie', 'author_id': 6600, 'author_profile': 'https://Stackoverflow.com/users/6600', 'pm_score': 4, 'selected': False, 'text': '<p>int is a C# keyword and is unambiguous.  </p>\n\n<p>Most of the time it doesn\'t matter but two things that go against Int32:</p>\n\n<ul>\n<li>You need to have a "using System;" statement.  using "int" requires no using statement.</li>\n<li>It is possible to define your own class called Int32 (which would be silly and confusing).  int always means int.</li>\n</ul>\n'}, {'answer_id': 62640, 'author': 'Keith', 'author_id': 905, 'author_profile': 'https://Stackoverflow.com/users/905', 'pm_score': 0, 'selected': False, 'text': '<p>It doesn\'t matter. int is the language keyword and Int32 its actual system type.</p>\n\n<p>See also my <a href="https://stackoverflow.com/questions/9734/cnet-case-insensitive-string#9747">answer here</a> to a related question.</p>\n'}, {'answer_id': 62649, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 2, 'selected': False, 'text': "<p>Once upon a time, the int datatype was pegged to the register size of the machine targeted by the compiler. So, for example, a compiler for a 16-bit system would use a 16-bit integer.</p>\n\n<p>However, we thankfully don't see much 16-bit any more, and when 64-bit started to get popular people were more concerned with making it compatible with older software and 32-bit had been around so long that for most compilers an <em>int</em> is just assumed to be 32 bits.</p>\n"}, {'answer_id': 62693, 'author': 'Ray Hayes', 'author_id': 7093, 'author_profile': 'https://Stackoverflow.com/users/7093', 'pm_score': 2, 'selected': False, 'text': '<p>int is the C# language\'s shortcut for System.Int32</p>\n\n<p>Whilst this does mean that Microsoft could change this mapping, a post on FogCreek\'s discussions stated <a href="http://discuss.fogcreek.com/dotnetquestions/default.asp?cmd=show&amp;ixPost=1988" rel="nofollow noreferrer">[source]</a></p>\n\n<p><em>"On the 64 bit issue -- Microsoft is indeed working on a 64-bit version of the .NET Framework but I\'m pretty sure int will NOT map to 64 bit on that system.</em>  </p>\n\n<p><em>Reasons:</em></p>\n\n<p><em>1. The C# ECMA standard specifically says that int is 32 bit and long is 64 bit.</em></p>\n\n<p><em>2. Microsoft introduced additional properties &amp; methods in Framework version 1.1 that return long values instead of int values, such as Array.GetLongLength in addition to Array.GetLength.</em></p>\n\n<p><em>So I think it\'s safe to say that all built-in C# types will keep their current mapping."</em></p>\n'}, {'answer_id': 62738, 'author': 'HasaniH', 'author_id': 7141, 'author_profile': 'https://Stackoverflow.com/users/7141', 'pm_score': 8, 'selected': True, 'text': '<p><a href="https://www.ecma-international.org/publications/standards/Ecma-334.htm" rel="noreferrer">ECMA-334</a>:2006 <em>C# Language Specification</em> (p18):</p>\n\n<blockquote>\n  <p>Each of the predefined types is shorthand for a system-provided type. For example, the keyword <code>int</code> refers to the struct <code>System.Int32</code>. As a matter of style, use of the keyword is favoured over use of the complete system type name.</p>\n</blockquote>\n'}, {'answer_id': 62800, 'author': 'raven', 'author_id': 4228, 'author_profile': 'https://Stackoverflow.com/users/4228', 'pm_score': 7, 'selected': False, 'text': "<p>They both declare 32 bit integers, and as other posters stated, which one you use is mostly a matter of syntactic style.  However they don't always behave the same way.  For instance, the C# compiler won't allow this:</p>\n\n<pre><code>public enum MyEnum : Int32\n{\n    member1 = 0\n}\n</code></pre>\n\n<p>but it will allow this:</p>\n\n<pre><code>public enum MyEnum : int\n{\n    member1 = 0\n}\n</code></pre>\n\n<p>Go figure.</p>\n"}, {'answer_id': 62937, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': "<p>I use int in the event that Microsoft changes the default implementation for an integer to some new fangled version (let's call it Int32b). </p>\n\n<p>Microsoft can then change the int alias to Int32b, and I don't have to change any of my code to take advantage of their new (and hopefully improved) integer implementation.</p>\n\n<p>The same goes for any of the type keywords.</p>\n"}, {'answer_id': 63128, 'author': 'HidekiAI', 'author_id': 7234, 'author_profile': 'https://Stackoverflow.com/users/7234', 'pm_score': 4, 'selected': False, 'text': '<p>Byte size for types is not too interesting when you only have to deal with a single language (and for code which you don\'t have to remind yourself about math overflows). The part that becomes interesting is when you bridge between one language to another, C# to COM object, etc., or you\'re doing some bit-shifting or masking and you need to remind yourself (and your code-review co-wokers) of the size of the data.</p>\n<p>In practice, I usually use Int32 just to remind myself what size they are because I do write managed C++ (to bridge to C# for example) as well as unmanaged/native C++.</p>\n<p>Long as you probably know, in C# is 64-bits, but in native C++, it ends up as 32-bits, or char is unicode/16-bits while in C++ it is 8-bits. But how do we know this? The answer is, because we\'ve looked it up in the manual and it said so.</p>\n<p>With time and experiences, you will start to be more type-conscientious when you do write codes to bridge between C# and other languages (some readers here are thinking &quot;why would you?&quot;), but IMHO I believe it is a better practice because I cannot remember what I\'ve coded last week (or I don\'t have to specify in my API document that &quot;this parameter is 32-bits integer&quot;).</p>\n<p>In <a href="http://en.wikipedia.org/wiki/F_Sharp_%28programming_language%29" rel="nofollow noreferrer">F#</a> (although I\'ve never used it), they define <em>int</em>, <em>int32</em>, and <em>nativeint</em>. The same question should rise, &quot;which one do I use?&quot;. As others has mentioned, in most cases, it should not matter (should be transparent). But I for one would choose int32 and uint32 just to remove the ambiguities.</p>\n<p>I guess it would just depend on what applications you are coding, who\'s using it, what coding practices you and your team follows, etc. to justify when to use Int32.</p>\n<p>Addendum:\nIncidentally, since I\'ve answered this question few years ago, I\'ve started using both F# and Rust.  F#, it\'s all about type-inferences, and bridging/InterOp\'ing between C# and F#, the native types matches, so no concern; I\'ve rarely had to explicitly define types in F# (it\'s almost a sin if you don\'t use type-inferences).  In Rust, they completely have removed such ambiguities and you\'d have to use <code>i32</code> vs <code>u32</code>; all  in all, reducing ambiguities helps reduce bugs.</p>\n'}, {'answer_id': 63143, 'author': 'Jim T', 'author_id': 7298, 'author_profile': 'https://Stackoverflow.com/users/7298', 'pm_score': 1, 'selected': False, 'text': '<p><code>int</code> is an alias for <code>System.Int32</code>, as defined in this table:\n<a href="http://msdn.microsoft.com/en-us/library/ya5y69ds.aspx" rel="nofollow noreferrer">Built-In Types Table (C# Reference)</a></p>\n'}, {'answer_id': 63395, 'author': 'Michael Meadows', 'author_id': 7643, 'author_profile': 'https://Stackoverflow.com/users/7643', 'pm_score': 0, 'selected': False, 'text': "<p>Using the <code>Int32</code> type requires a namespace reference to <code>System</code>, or fully qualifying (<code>System.Int32</code>).  I tend toward <code>int</code>, because it doesn't require a namespace import, therefore reducing the chance of namespace collision in some cases. When compiled to IL, there is no difference between the two.</p>\n"}, {'answer_id': 63469, 'author': 'Chris Pietschmann', 'author_id': 7831, 'author_profile': 'https://Stackoverflow.com/users/7831', 'pm_score': 0, 'selected': False, 'text': '<p>Also consider Int16. If you need to store an Integer in memory in your application and you are concerned about the amount of memory used, then you could go with Int16 since it uses less memeory and has a smaller min/max range than Int32 (which is what int is.)</p>\n'}, {'answer_id': 63860, 'author': 'Remi Despres-Smyth', 'author_id': 8169, 'author_profile': 'https://Stackoverflow.com/users/8169', 'pm_score': 6, 'selected': False, 'text': '<p>I always use the system types - e.g., <code>Int32</code> instead of <code>int</code>. I adopted this practice after reading <em><a href="https://rads.stackoverflow.com/amzn/click/com/0735614229" rel="nofollow noreferrer" rel="nofollow noreferrer">Applied .NET Framework Programming</a></em> - author Jeffrey Richter makes a good case for using the full type names.  Here are the two points that stuck with me:</p>\n\n<ol>\n<li><p>Type names can vary between .NET languages. For example, in C#, <code>long</code> maps to System.Int64 while in C++ with managed extensions, <code>long</code> maps to Int32. Since languages can be mixed-and-matched while using .NET, you can be sure that using the explicit class name will always be clearer, no matter the reader\'s preferred language.</p></li>\n<li><p>Many framework methods have type names as part of their method names:</p>\n\n<pre><code>BinaryReader br = new BinaryReader( /* ... */ );\nfloat val = br.ReadSingle();     // OK, but it looks a little odd...\nSingle val = br.ReadSingle();    // OK, and is easier to read\n</code></pre></li>\n</ol>\n'}, {'answer_id': 64031, 'author': 'yhdezalvarez', 'author_id': 8013, 'author_profile': 'https://Stackoverflow.com/users/8013', 'pm_score': 2, 'selected': False, 'text': '<p>You shouldn\'t care. You should use <code>int</code> most of the time. It will help the porting of your program to a wider architecture in the future (currently <code>int</code> is an alias to <code>System.Int32</code> but that could change). Only when the bit width of the variable matters (for instance: to control the layout in memory of a <code>struct</code>) you should use <code>int32</code> and others (with the associated "<code>using System;</code>").</p>\n'}, {'answer_id': 64342, 'author': 'Schmuli', 'author_id': 8363, 'author_profile': 'https://Stackoverflow.com/users/8363', 'pm_score': 0, 'selected': False, 'text': '<p>A while back I was working on a project with Microsoft when we had a visit from someone on the Microsoft .NET CLR product team. This person coded examples and when he defined his variables he used “Int32” vs. “int” and “String” vs. “string”.</p>\n<p>I had remembered seeing this style in other example code from Microsoft.  So, I did some research and found that everyone says that there is no difference between the “Int32” and “int” except for syntax coloring. In fact, I found a lot of material suggesting you use “Int32” to make your code more readable. So, I adopted the style.</p>\n<p>The other day I did find a difference! The compiler doesn’t allow you to type enum using the “Int32”, but it does when you use “int”. Don’t ask me why because I don’t know yet.</p>\n<p>Example:</p>\n<pre><code>public  enum MyEnum : Int32\n{\n    AEnum = 0\n}\n</code></pre>\n<p>This works.</p>\n<pre><code>public enum MyEnum : int\n{\n    AEnum = 0\n}\n</code></pre>\n<p>Taken from: <a href="https://web.archive.org/web/20200119050036/http://geekswithblogs.net:80/caustin/archive/2005/08/05/49267.aspx" rel="nofollow noreferrer">Int32 notation vs. int</a></p>\n'}, {'answer_id': 66648, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>Though they are (mostly) identical (see below for the one [bug] difference), you definitely should care and you should use Int32.</p>\n\n<ul>\n<li><p>The name for a 16-bit integer is Int16. For a 64 bit integer it\'s Int64, and for a 32-bit integer the intuitive choice is: int or Int32?</p></li>\n<li><p>The question of the size of a variable of type Int16, Int32, or Int64 is self-referencing, but the question of the size of a variable of type int is a perfectly valid question and questions, no matter how trivial, are distracting, lead to confusion, waste time, hinder discussion, etc. (the fact this question exists proves the point).</p></li>\n<li><p>Using Int32 promotes that the developer is conscious of their choice of type. How big is an int again? Oh yeah, 32. The likelihood that the size of the type will actually be considered is greater when the size is included in the name. Using Int32 also promotes knowledge of the other choices. When people aren\'t forced to at least recognize there are alternatives it become far too easy for int to become "THE integer type".</p></li>\n<li><p>The class within the framework intended to interact with 32-bit integers is named Int32. Once again, which is: more intuitive, less confusing, lacks an (unnecessary) translation (not a translation in the system, but in the mind of the developer), etc.  <code>int lMax = Int32.MaxValue</code> or <code>Int32 lMax = Int32.MaxValue</code>?</p></li>\n<li><p>int isn\'t a keyword in all .NET languages.</p></li>\n<li><p>Although there are arguments why it\'s not likely to ever change, int may not always be an Int32.</p></li>\n</ul>\n\n<p>The drawbacks are two extra characters to type and [bug].</p>\n\n<p>This won\'t compile</p>\n\n<pre><code>public enum MyEnum : Int32\n{\n    AEnum = 0\n}\n</code></pre>\n\n<p>But this will:</p>\n\n<pre><code>public enum MyEnum : int\n{\n    AEnum = 0\n}\n</code></pre>\n'}, {'answer_id': 69661, 'author': 'bovium', 'author_id': 11135, 'author_profile': 'https://Stackoverflow.com/users/11135', 'pm_score': 0, 'selected': False, 'text': '<p>Use of Int or Int32 are the same Int is just sugar to simplify the code for the reader.</p>\n\n<p>Use the Nullable variant Int? or Int32? when you work with databases on fields containing null. That will save you from a lot of runtime issues.</p>\n'}, {'answer_id': 69739, 'author': 'user11211', 'author_id': 11211, 'author_profile': 'https://Stackoverflow.com/users/11211', 'pm_score': 0, 'selected': False, 'text': "<p>Some compilers have different sizes for int on different platforms (not C# specific)</p>\n\n<p>Some coding standards (MISRA C) requires that all types used are size specified (i.e. Int32 and not int).</p>\n\n<p>It is also good to specify prefixes for different type variables (e.g. b for 8 bit byte, w for 16 bit word, and l for 32 bit long word => Int32 lMyVariable)</p>\n\n<p>You should care because it makes your code more portable and more maintainable.</p>\n\n<p>Portable may not be applicable to C# if you are always going to use C# and the C# specification will never change in this regard.</p>\n\n<p>Maintainable ihmo will always be applicable, because the person maintaining your code may not be aware of this particular C# specification, and miss a bug were the int occasionaly becomes more than 2147483647.</p>\n\n<p>In a simple for-loop that counts for example the months of the year, you won't care, but when you use the variable in a context where it could possibly owerflow, you should care.</p>\n\n<p>You should also care if you are going to do bit-wise operations on it.</p>\n"}, {'answer_id': 146672, 'author': 'Mark A. Nicolosi', 'author_id': 1103052, 'author_profile': 'https://Stackoverflow.com/users/1103052', 'pm_score': 3, 'selected': False, 'text': '<p>I always use the aliased types (int, string, etc.) when defining a variable and use the real name when accessing a static method:</p>\n\n<pre><code>int x, y;\n...\nString.Format ("{0}x{1}", x, y);\n</code></pre>\n\n<p>It just seems ugly to see something like int.TryParse(). There\'s no other reason I do this other than style.</p>\n'}, {'answer_id': 367420, 'author': 'devstuff', 'author_id': 41321, 'author_profile': 'https://Stackoverflow.com/users/41321', 'pm_score': 2, 'selected': False, 'text': '<p>I\'d recommend using Microsoft\'s <a href="http://code.msdn.microsoft.com/sourceanalysis" rel="nofollow noreferrer">StyleCop</a>.</p>\n\n<p>It is like <a href="http://en.wikipedia.org/wiki/FxCop" rel="nofollow noreferrer">FxCop</a>, but for style-related issues. The default configuration matches Microsoft\'s internal style guides, but it can be customised for your project.</p>\n\n<p>It can take a bit to get used to, but it definitely makes your code nicer.</p>\n\n<p>You can include it in your build process to automatically check for violations.</p>\n'}, {'answer_id': 17448373, 'author': 'Selim', 'author_id': 2546603, 'author_profile': 'https://Stackoverflow.com/users/2546603', 'pm_score': 0, 'selected': False, 'text': '<p>According to the Immediate Window in Visual Studio 2012 Int32 is int, Int64 is long. Here is the output:</p>\n\n<pre><code>sizeof(int)\n4\nsizeof(Int32)\n4\nsizeof(Int64)\n8\nInt32\nint\n    base {System.ValueType}: System.ValueType\n    MaxValue: 2147483647\n    MinValue: -2147483648\nInt64\nlong\n    base {System.ValueType}: System.ValueType\n    MaxValue: 9223372036854775807\n    MinValue: -9223372036854775808\nint\nint\n    base {System.ValueType}: System.ValueType\n    MaxValue: 2147483647\n    MinValue: -2147483648\n</code></pre>\n'}, {'answer_id': 69175392, 'author': 'Karl Stephen', 'author_id': 2410892, 'author_profile': 'https://Stackoverflow.com/users/2410892', 'pm_score': 0, 'selected': False, 'text': "<p>It's 2021 and I've read all answers. Most says it's basically the same (it's an alias), or, it depends on &quot;what you like&quot;, or &quot;by convention use int...&quot; No answer gives you a clear <strong>when</strong>, <strong>where</strong> and <strong>why</strong> use <code>Int32</code> over <code>int</code>. That's why I'm here.</p>\n<p>98% of the time, you can get away with <code>int</code>, and that's perfectly fine. <strong>What are the other 2%</strong> ?</p>\n<p><strong>IO with records</strong> (struct, native types, organization and compression). Someone said <em>an useless application is one that can read and manipulate data, but not actually capable of writing new datas</em> to a defined storage. But in order to not reinvent the wheel, at some point, those dealing with <strong>old datas</strong> has to retrieve the documentation on how to read them. And chances are they were compiled from an era where <strong>a <code>long</code> was always a 32-bits integer</strong>.</p>\n<p>It happenned before, where some had trouble remembering a <code>db</code> is a byte, a <code>dw</code> is a word, a <code>dd</code> is a double word, but how many bits was that about ? And <strong>that will likely happen again</strong> on <code>C# 43.0</code> on a <code>256-bits</code> platform... where the (future) boys never heard of &quot;<em>by convention, use int instead of Int32</em>&quot;. That's the 2% where <code>Int32</code> matters over <code>int</code>. MSDN saying today it's recommended to use <code>int</code> is irrelevant, it usually works with current C# version, but that may get dropped in future MSDN pages, in 2028, or 2034 ? Fewer and fewer people have <code>WORD</code> and <code>DWORD</code> encouters today, yet, two decades ago, they were common. The same thing will happen to <code>int</code>, in the very case of dealing with precise-fixed-length data.</p>\n<p><strong>In memory</strong>, a <code>ushort</code> (<code>UInt16</code>) can be a <code>Decimal</code> as long as it's fractional part is null, it is positive or null, and does not exceed 65535. <strong>But inside a file</strong>, it must be a <code>short</code>, 16-bits long. And when you read a documentation about a file structure from another era (inside the source code), you realize <strong>there are 3545 records definitions</strong>, some nested inside others, each record having between a couple and <strong>hundreds of fields</strong> of varying types.</p>\n<p>Somewhere in 2028 a boy thought <strong>he could just get away by Ctrl-H-ing</strong> <code>int</code> to <code>Int32</code>, whole word only and match case... ~67000 changes in whole solution. Hit Run and still get CTDs. Clap clap clap. Go figure which <code>int</code> you should have changed to <code>Int32</code> and which ones you should have changed to <code>var</code>. Also worth to point out <code>Pointers</code> are useful, when you deal with terabytes of datas (have a virtual representation of an entire planet on some cloud, download on demand, and render to user screen). Pointers are really fast in the ~1% of cases where there are so many datas to compute in realtime, you must trade with unsafe code. Again, it's to come up with an actually useful application, instead of being fancy and waste time porting to managed. So, be carefull, <code>IntPtr</code> is 32-bits or 64-bits already ? Could you get away with your code without caring how many bytes you read/skip ? Or just go <code>(Int32*) int32Ptr = (Int32*) int64Ptr;</code>...</p>\n<p><strong>An even more factual example</strong> is a file containing data processing and their respective commands (methods in the source code), like internal branching (a conditional continue or jump to if the test fails) :</p>\n<p><code>IfTest</code> record in file says : if value equals someConstant, jump to <code>address</code>. Where <code>address</code> is a <code>16-bits</code> integer representing a relative pointer inside the file (you can go back towards the start of the file up to 32768 bytes, or up to 32767 bytes further down). But 10 years later, platforms can handle larger files and larger datas, and now you have <code>32-bits</code> relative address. Your method in the source code were named <code>IfTestMethod(...)</code>, now how would you name the new one ? <code>IfTestMethodInt()</code> or <code>IfTestMethod32()</code> ? Would you also rename the old method <code>IfTestMethodShort()</code> or <code>IfTestMethod16()</code> ? Then a decade later, you get a new command with long (Int64) relative address... What about a 128 bits command some 10 years later ? <strong>Be consistent</strong> ! Principles are great, but sometimes logic is better.</p>\n<p><strong>The problem is not</strong> me or you writing a code <strong>today</strong>, and it appears okay to us. It is being in the place of the one guy trying to understand what we wrote, <strong>10 or 20 years later</strong>, <strong>how much it costs</strong> in time (= money) to come up with a working updated code ? Being explicit or writing redundant comments will actually save time. Which one you prefer ? <code>Int32 val;</code> or <code>var val; // 32-bits</code>.</p>\n<p>Also, working with <strong>foreign data from other platforms or compile directives</strong> is a concept (today involves Interop, COM, PInvoke...) And that's a concept <strong>we cannot get rid of</strong>, whatever the era, because it takes time to update (reformat) datas (via serialization for ex.) Upgrading DLLs to managed code also takes time. We took time to leave assembler behind and go full-C. We are taking time to move from 32-bits datas to 64-bits, yet, we still need to care about 8 and 16-bits. What next in the future ? Move from 128-bits to 256 or directly to 1024 ? Do not assume a keyword explicit to you will remain explicit for the guys reading your documentation 20 years later (and documentation usually contains errors, mainly because of copy/paste).</p>\n<p><em>So here it is : Where to use Int32 <strong>today</strong> over int ?</em></p>\n<p>It's when you are producing code that is <strong>data-size sensible</strong> (IO, network, cross-platform data...), and <strong>at some point in the future</strong> - could be decades later - someone will have to understand and port your code. The key reason is era-based. 1000 lines of code, it's okay to use <code>int</code>, 100000 lines, <strong>it's not anymore</strong>. That's a rare duty <strong>only a few</strong> will have to do, and hell yeah, they have struggle, if only some were a little more explicit instead of relying on &quot;<em>by convention</em>&quot; or &quot;<em>it looks pretty in the IDE, Int32 is so ugly</em>&quot; or &quot;<em>they are the same, don't bother, it's a waste of time to write that two numbers and holding shift key</em>&quot;, or &quot;<em>int is unambiguous</em>&quot;, or &quot;<em>those who don't like int are just VB fanboys - go learn C# you noob</em>&quot; (yeah, that's the underlying meaning of a few comments right here)</p>\n<p><strong>Do not take what I wrote as a generalized perception, nor an attempt to promote Int32 on all cases</strong>. I clearly stated the specific case (as it seems to me this was not clear from other answers), to advocate for the few ones getting blammed by their supervisors for being fancy writing <code>Int32</code>, and at the same time the very same supervisor not understanding what takes so long to rewrite that C DLL to C#. It's an edge case, but at least for those reading, <strong>&quot;Int32&quot; has at least one purpose in its life</strong>.</p>\n<p>The point can be further discussed by turning the question the other way around : <em>Why not just get rid of <code>Int32</code>, <code>Int64</code> and all the other variants in future C# specifications ? What that would imply ?</em></p>\n"}]
['https://Stackoverflow.com/questions/62503', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1826/']