Comments on: Elegant one-line way to use TryParse https://izabelawlodarska.com/2018/04/15/elegant-one-line-way-to-use-tryparse/#utm_source=rss&utm_medium=rss&utm_campaign=elegant-one-line-way-to-use-tryparse Follow me for architecture, .net, sitecore and software engineering tips Wed, 16 Mar 2022 11:31:51 +0000 hourly 1 https://wordpress.org/?v=6.9.4 By: TPAKTOPA https://izabelawlodarska.com/2018/04/15/elegant-one-line-way-to-use-tryparse/comment-page-1/#comment-23 Wed, 16 Mar 2022 11:31:51 +0000 http://www.izabelawlodarska.com/?p=225#comment-23 thank you, I use this construction:

.int value= int.TryParse(valueToParseFromString, out value) ? value: 0;.

]]>
By: DevD https://izabelawlodarska.com/2018/04/15/elegant-one-line-way-to-use-tryparse/comment-page-1/#comment-9 Thu, 11 Nov 2021 17:56:14 +0000 http://www.izabelawlodarska.com/?p=225#comment-9 This is still great, use it all the time! Only thing that’s changed that can make this one-liner more elegant is by removing the ‘int value’ declaration before the parse, add the ‘int’ datatype to the out variable ie:

if (!int.TryParse(valueToParseFromString, out int value)
value = 0;

//dostuffwithvaluenow

]]>
By: Brent https://izabelawlodarska.com/2018/04/15/elegant-one-line-way-to-use-tryparse/comment-page-1/#comment-4 Fri, 31 May 2019 14:22:37 +0000 http://www.izabelawlodarska.com/?p=225#comment-4 No longer required. Variable declaration can now be used within TryParse.

https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7#out-variables

]]>
By: Travis https://izabelawlodarska.com/2018/04/15/elegant-one-line-way-to-use-tryparse/comment-page-1/#comment-2 Fri, 17 Aug 2018 14:11:28 +0000 http://www.izabelawlodarska.com/?p=225#comment-2 I agree completely. Nice 🙂

]]>