Linked Questions
26 questions linked to/from Parse v. TryParse
-4 votes
2 answers
961 views
Int32.Parse vs Int32.TryParse [duplicate]
People have been suggesting to use Int32.TryParse but I found out that in case of any string such as "4e",it would give me output 0(i would directly print my input),whereas Int32.Parse would give an ...
0 votes
3 answers
143 views
How can I return a 0 from a function that parses a string to find an int if it finds a number with a decimal point? [duplicate]
I have this code: public int GetIntSetting(Settings setting, int nullState) { var s = GetStringSetting(setting); if (string.IsNullOrEmpty(s)) return nullState; return int.Parse(s);...
0 votes
3 answers
158 views
How to add <= or >= to a int.Parse [duplicate]
I am doing something where I want a user to be able to enter a number between 0-9 and it spits out the word for it, eg. 1 into one. I am fine with the first part, however, I don't know how to get it ...
2 votes
3 answers
106 views
How can I handle an exception in C#? [duplicate]
I'm trying to handle an exception to avoid my program crash if double.Parse(string) tries parsing invalid values (such as strings instead of numbers). Here's what I've got: do { //asking customer ...
0 votes
0 answers
47 views
Console.Readline() to integer conversion [duplicate]
What I am trying to achieve is write a very simple console program that continuously asks the user to enter a number or "ok" if he wants to exit. When he enters ok, the sum of all the ...
49 votes
15 answers
38k views
What is fastest: (int), Convert.ToInt32(x) or Int32.Parse(x)?
Which of the following code is fastest/best practice for converting some object x? int myInt = (int)x; or int myInt = Convert.ToInt32(x); or int myInt = Int32.Parse(x); or in the case of a string '...
53 votes
9 answers
382k views
How can I read user input from the console?
I want to get a number from the user, and then multiply that number with Pi. my attempt at this is below. But a contains gibberish. For example, if I insert 22, then a contains 50. What am I doing ...
25 votes
5 answers
17k views
Data Type Recognition/Guessing of CSV data in python
My problem is in the context of processing data from large CSV files. I'm looking for the most efficient way to determine (that is, guess) the data type of a column based on the values found in that ...
6 votes
3 answers
17k views
Cannot implicitly convert type 'string' to 'decimal'
private void button18_Click(object sender, EventArgs e) { Form1 stForm = new Form1(); DialogResult result = stForm.ShowDialog(this); if (result == DialogResult.Cancel) ...
1 vote
5 answers
2k views
Regex C# console app
How do I add a regular expression which will accept decimal places (5.23) but nothing else in a break like so? i.e handle only numbers and decimal places which will throw an error if anything other ...
3 votes
4 answers
8k views
Converting string to int (or something else), is there a prefered way?
Sometimes i wonder, when converting strings to other types, for example int32, is one way better than the other, or is it just a matter of taste? Convert.ToInt32("123") or Int32.Parse("123") or ...
0 votes
4 answers
4k views
Creating column with user defined constraint
I want to limit my varchar columns to have only ascii characters within a specified range, say 0-9 or A-F (for hex characters) What would my constraint look like?
2 votes
4 answers
660 views
try catch not working
I can't figure out how to get the try catch to work. Need to have an error message box pop up when a non number is entered in the text boxes. private void btnAdd_Click(object sender, EventArgs e) ...
0 votes
3 answers
5k views
String Comparison or Parse to Int?
I'll keep this one short. I'm writing a module which will be required to compare two large integers which are input as strings (note: they are large, but not large enough to exceed Int64 bounds). ...
1 vote
2 answers
3k views
Convert.ToDouble() throws Format Exception
I am reading Data from an internal Database. The code assigns value read from the database to double. if (Convert.ToDouble(PricefromString) == Price && PriceFound == false) PricefromString ...