317 questions
0 votes
1 answer
96 views
C#: Trying to check what type an object is, is there any method like TryParse that takes in an object type?
I am working on a chess game in unity. I have a multidimensional array of objects called a board that gives me the the array with either a Piece Object(custom) or an integer i.e. 0. I want to check if ...
2 votes
1 answer
85 views
How to write date format which will cover all precisions or length of milliseconds of DateTime.UtcNow?
Sometimes DateTime.UtcNow returns me different length of milliseconds: 2025-02-27T06:01:59.7581509Z 2025-02-27T06:21:48.190694Z The difference is between length of milliseconds. So 7581509 has length ...
0 votes
0 answers
38 views
How do i do in C# that if the user types not a number it writes invalid input and if its a number it continues? [duplicate]
I Am Making A Mini Game That Is Not Important But Here Is What I Got Rn That's What It Looks Lik If (Int.tryparse(userinput2, Out Idk What Out Means)) Like I Said I Tried This Method And I Don't Want ...
0 votes
0 answers
51 views
Why does DateTime.TryParse fail to parse negative (-ve) years for BC/BCE dates in ISO 8601 date format
I've built a plot of influential people across history on a timeline using C# in Unity3D. I run a Validate() method over the .json and then construct gameobjects. The code successfully plots people ...
-1 votes
2 answers
125 views
c# variable culture string to invariant culture double [closed]
I have found many questions for this topic but I couldn't find one that covers my case. For a string input, which may be or may not be a real number of unknown culture, how can I try to cast it to a ...
-2 votes
1 answer
155 views
Parsing "dd MMMM, yyyy" using DateTime.TryParseExact [closed]
I'm working with TryParseExact but it's throwing an error. What could be the issue? Thanks DateTime result; if (DateTime.TryParseExact("31 December, 2023", ["'dd MMMM, yyyy'"], ...
-1 votes
2 answers
176 views
TryParseExact does not convert a string with timezone
I have a string "2023-04-13T07:03:20-03:00", and I want to convert to DateTime with a specific format "yyyy-MM-ddTHH:mm:ss", so i'm using the TryParseExact method, but I just ...
1 vote
1 answer
397 views
DateTime.TryParseExact Doesn't Work With Single-Digit Day or Month, Regardless of Format String
I'm trying to implement a TextBox validation for user input of dates. Long story short, I'm building a new application and the users are accustomed to entering dates this way, so I want to try and ...
0 votes
1 answer
69 views
How do I run this code without using try catch?
WriteLine("Before parsing"); Write("What is your age? "); string? input = ReadLine(); // or use "49" in a notebook try { int age = int.Parse(input!); WriteLine($&...
-1 votes
2 answers
205 views
How to handle Unhandled exceptions in c# using TryParse
if (response.ToLower() == "addition") { Console.Write("Enter a number: "); double num1 = double.Parse(Console.ReadLine()); Console.Write("Enter another number: "); ...
0 votes
1 answer
104 views
Double tryparse return value is inconsistent
I have a strange problem. When my custom formatted Hex value is tested with double.Tryparse it returns inconsistent results For example if (double.TryParse(dblValue, NumberStyles.Float, CultureInfo....
0 votes
2 answers
363 views
Use dynamic data type for TryParse
I have a process that allows users to upload data in Excel file and save to database once the data have gone series of validations . Once such validation is data type validation, to prevent them ...
-1 votes
1 answer
198 views
how to change NAN to 0 in vb.net
I want to change the NAN result in the text label to 0. is there a solution in the recommendation?. Thanks Private Sub Calculatedispercent() Dim DisTotal As Double Dim Total As ...
3 votes
2 answers
2k views
C# Parse DateTime using DateTime.TryParseExact() multiple format
I have a string text that i want to parse/convert to DateTime, the text can have a different formats (depending on the user who write it), it can be "dd/MM/yyyy" or it can be "MM/dd/...
-2 votes
1 answer
39 views
Spliting numerical input by linebreak in a textbox, doing some math on it, and outputting results in a new textbox
I'm attempting to create a wpf app that takes a list of numerical values, separated by line breaks, in one textbox. You click a button, and it outputs the new numerical values into a second textbox. I'...