C
C#

help

❔ check if string is valid guid without guid.TryParse

CCrosRoad9511/12/2022
as in title, i would like to avoid conditions like if (!Guid.TryParse(string, out var _)), instead i want something like if (!Guid.IsValid(string))
UUUnknown User11/12/2022
2 Messages Not Public
Sign In & Join Server To View
Pplam11/12/2022
TryParse would be great here, but as you've mentioned to avoid it, here's what you can actually do:
public static class Example {
public static bool TryParseGuid(string guidString, out Guid guid)
{
if (guidString == null) throw new ArgumentNullException("guidString");
try
{
guid = new Guid(guidString);
return true;
}
catch (FormatException)
{
guid = default(Guid);
return false;
}
}
}
public static class Example {
public static bool TryParseGuid(string guidString, out Guid guid)
{
if (guidString == null) throw new ArgumentNullException("guidString");
try
{
guid = new Guid(guidString);
return true;
}
catch (FormatException)
{
guid = default(Guid);
return false;
}
}
}
TThinker11/12/2022
That's just a slower version of TryParse
Pplam11/12/2022
ikr?
CCrosRoad9511/12/2022
so i will stick with guid.tryparse 😄
UUUnknown User11/12/2022
2 Messages Not Public
Sign In & Join Server To View
AAccord11/22/2022
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
❔ .NET CORE 6 servicesSo i want add a service "AddContentful" but idk how to fix this because i can only find configuratio❔ Console Game Project (Memory Matching)Hi all! I'm not sure if this is the right channel, but I have a question... I'm New to programming (Find all HREFs out of string and extract valueHey, I am currently developing a web scraper and therefore want to extract all available information❔ How to store session data backend?I'm building a similar game to skribbl.io which is a drawing game where you draw with other people. ❔ How do i sort a list of objects by multiple possible itemsHey, i'm trying to write a method to return a list of objects by letting the user choose which item ❔ ASP.NET Core how to let a controller be mapped only in development modeThis is pretty easy to do with minimal API's, you just do a check and map only if it succeeds: ```cs❔ Turn off VS 2022 PreviewHow do I turn off VS 2022 Preview? It is showing on the splash screen and everywhere. I turned it on❔ Winforms rotated text in `ToolStripButton` appears boldWhen setting the direction of text to e.g. Vertical270, the text in the button becomes different, eiIf I do console.clear() it just skips a bunch of lines instead of clearingI am using vsc c# and I think its an error with .net because I saw a few forums talking about it, pl❔ Why wont visual studio auto format this with CTRL K + CTRL D?can anyone think of why visual studio wont format these lambda arrows with `CTRL K + CTRL D` but it ❔ Changing TextBlock Background property in a static methodThe method needs to be static (unless there are implementations of LowLevelKeyboardProc that doesn't❔ SQLite with Muai ensure connectionstring to DB for all devicesIm running SQLite db and i want the connection to the DB to point to the same file no matter if i ru❔ IEnumerable is empty for some reasonI want to add a filter to check if an IEnumerable is empty so i'm using IEnumerable.Any(), but my IEMy code is stuck in a infinity loop [Answered]https://github.com/AbdulRaheemNazir/MiniApps/blob/main/Just%20need%20random%20Symbol When I try to ❔ How can I check if any element of a list is in another list?I know i could do it with a for loop, but it seems overkill to do something that simple :/❔ How to parse a json response?.❔ Task.WhenAll for Tests, and other async questionsIn xUnit, there is no support for testing async or in parallel within the same collection, where a cEntity Framework Core DB issues [Answered]Introducing FOREIGN KEY constraint 'FK_Sections_Teachers_TeacherID' on table 'Sections' may cause cy❔ Reverse proxy + controllers ordering issuesPlease help https://github.com/microsoft/reverse-proxy/discussions/792#discussioncomment-4119355❔ where generic is itypea or itypebIs there syntax to check weather a generic attribute is either of two interface types? Pseudo: Wher