<p>Are all of these equal?  Under what circumstances should I choose each over the others?</p>

<ul>
<li><p>var.ToString()</p></li>
<li><p>CStr(var)</p></li>
<li><p>CType(var, String)</p></li>
<li><p>DirectCast(var, String)</p></li>
</ul>

<hr>

<p><em>EDIT: Suggestion from <strong><a href="https://stackoverflow.com/users/303/notmyself">NotMyself</a></strong>&hellip;</em></p>

<ul>
<li>TryCast(var, String)</li>
</ul>

[{'answer_id': 40771, 'author': 'NotMyself', 'author_id': 303, 'author_profile': 'https://Stackoverflow.com/users/303', 'pm_score': 3, 'selected': False, 'text': '<p>I prefer the following syntax:</p>\n\n<pre><code>Dim number As Integer = 1\nDim str As String = String.TryCast(number)\n\nIf str IsNot Nothing Then\n</code></pre>\n\n<p>Hah you can tell I typically write code in C#. 8) </p>\n\n<p>The reason I prefer TryCast is you do not have to mess with the overhead of casting exceptions. Your cast either succeeds or your variable is initialized to null and you deal with that accordingly.</p>\n'}, {'answer_id': 40782, 'author': 'bdukes', 'author_id': 2688, 'author_profile': 'https://Stackoverflow.com/users/2688', 'pm_score': 8, 'selected': True, 'text': '<p>Those are all slightly different, and generally have an acceptable usage.</p>\n\n<ul>\n<li><code>var.</code><a href="http://msdn.microsoft.com/en-us/library/system.object.tostring.aspx" rel="noreferrer"><code>ToString</code></a><code>()</code> is going to give you the string representation of an object, regardless of what type it is.  Use this if <code>var</code> is not a string already.</li>\n<li><a href="http://msdn.microsoft.com/en-us/library/0zk841e9.aspx" rel="noreferrer"><code>CStr</code></a><code>(var)</code> is the VB string cast operator.  I\'m not a VB guy, so I would suggest avoiding it, but it\'s not really going to hurt anything.  I think it is basically the same as <code>CType</code>.</li>\n<li><a href="http://msdn.microsoft.com/en-us/library/4x2877xb.aspx" rel="noreferrer"><code>CType</code></a><code>(var, String)</code> will convert the given type into a string, using any provided conversion operators.</li>\n<li><a href="http://msdn.microsoft.com/en-us/library/7k6y2h6x.aspx" rel="noreferrer"><code>DirectCast</code></a><code>(var, String)</code> is used to up-cast an object into a string.  If you know that an object variable is, in fact, a string, use this.  This is the same as <code>(string)var</code> in C#.</li>\n<li><a href="http://msdn.microsoft.com/en-us/library/zyy863x8.aspx" rel="noreferrer"><code>TryCast</code></a> (as mentioned by @<a href="https://stackoverflow.com/questions/40764/how-should-i-cast-in-vbnet#40771">NotMyself</a>) is like <code>DirectCast</code>, but it will return <code>Nothing</code> if the variable can\'t be converted into a string, rather than throwing an exception.  This is the same as <code>var as string</code> in C#.  The <code>TryCast</code> page on MSDN has a good comparison, too.</li>\n</ul>\n'}, {'answer_id': 40797, 'author': 'OwenP', 'author_id': 2547, 'author_profile': 'https://Stackoverflow.com/users/2547', 'pm_score': 3, 'selected': False, 'text': '<p><a href="http://msdn.microsoft.com/en-us/library/s2dy91zy%28VS.80%29.aspx" rel="noreferrer">MSDN</a> seems to indicate that the Cxxx casts for specific types can improve performance in VB .NET because they are converted to inline code.  For some reason, it also suggests <a href="http://msdn.microsoft.com/en-us/library/7k6y2h6x.aspx" rel="noreferrer">DirectCast</a> as opposed to CType in certain cases (the documentations states it\'s when there\'s an inheritance relationship; I believe this means the sanity of the cast is checked at compile time and optimizations can be applied whereas CType always uses the VB runtime.)</p>\n\n<p>When I\'m writing VB .NET code, what I use depends on what I\'m doing. If it\'s prototype code I\'m going to throw away, I use whatever I happen to type.  If it\'s code I\'m serious about, I try to use a Cxxx cast.  If one doesn\'t exist, I use DirectCast if I have a reasonable belief that there\'s an inheritance relationship.  If it\'s a situation where I have no idea if the cast should succeed (user input -> integers, for example), then I use TryCast so as to do something more friendly than toss an exception at the user.</p>\n\n<p>One thing I can\'t shake is I tend to use ToString instead of CStr but supposedly Cstr is faster. </p>\n'}, {'answer_id': 46578, 'author': 'joek1975', 'author_id': 4770, 'author_profile': 'https://Stackoverflow.com/users/4770', 'pm_score': 0, 'selected': False, 'text': '<p>At one time, I remember seeing the MSDN library state to use CStr() because it was faster. I do not know if this is true though.</p>\n'}, {'answer_id': 103466, 'author': 'Zack Peterson', 'author_id': 83, 'author_profile': 'https://Stackoverflow.com/users/83', 'pm_score': 2, 'selected': False, 'text': '<p>User <a href="https://stackoverflow.com/users/1968/konrad-rudolph">Konrad Rudolph</a> advocates <a href="https://stackoverflow.com/questions/102084/hidden-features-of-vbnet#103285">for DirectCast() in Stack Overflow question "Hidden Features of VB.NET"</a>.</p>\n'}, {'answer_id': 318669, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 4, 'selected': False, 'text': '<p><code>Cstr()</code> is compiled inline for better performance.</p>\n\n<p><code>CType</code> allows for casts between types if a conversion operator is defined</p>\n\n<p><code>ToString()</code> Between base type and string throws an exception if conversion is not possible.</p>\n\n<p><code>TryParse()</code> From String to base <code>typeif</code> possible otherwise returns false</p>\n\n<p><code>DirectCast</code> used if the types are related via inheritance or share a common interface , will throw an exception if the cast is not possible, <code>trycast</code> will return nothing in this instance</p>\n'}, {'answer_id': 5330177, 'author': 'SickPuP', 'author_id': 580355, 'author_profile': 'https://Stackoverflow.com/users/580355', 'pm_score': 1, 'selected': False, 'text': '<p>According to the certification exam you should use Convert.ToXXX() whenever possible for simple conversions because it optimizes performance better than CXXX conversions.  </p>\n'}]
['https://Stackoverflow.com/questions/40764', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/83/']