It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
When i read from the XML file, i read it like this and it works,
decimal checkkkk = Config.Location.test.Longitude;
textBox3.Text = checkkkk.ToString(CultureInfo.InvariantCulture);
I want to write it back to the same XML file, I'm getting a error at this point..!
decimal value;
Configs.Location.test.Longitude =
decimal.TryParse(textBox3.Text, NumberStyles.Any, CultureInfo.InvariantCulture.NumberFormat, out value);
What is the mistake?
The method Decimal.TryParse returns the boolean data-type and not decimal.
Decimal.TryParse, Converts the string representation of a number to its Decimal equivalent using the specified style and culture-specific format. A return value indicates whether the conversion succeeded or failed.
Try to do it this way instead:
decimal value;
if (decimal.TryParse(textBox3.Text, NumberStyles.Any, CultureInfo.InvariantCulture.NumberFormat, out value))
{
rseConfigs.RseLocation.GpsCoordinates.Longitude = value;
}
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
In my class partData the FW_Step attribute isfrom the type double?
When I try to format it like that
partData.FW_Step.Value.ToString("F3")
It's fail when the value is null
How can I use the format when the value is null?
You can't format when it's null; hopefully the reasons why are obvious. You need to check for the value first:
string formattedValue;
if (partData.FW_Step.HasValue)
formattedValue = partData.FW_Step.Value.ToString("F3");
else
formattedValue = "default value for null";
You can make this code shorter using a ternary expression:
string formattedValue = partData.FW_Step.HasValue ? partData.FW_Step.Value.ToString("F3") : "default value for null";
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I have a string variable which has the value that the user taps. I need to make another variable which its name will be the string's value.
How do / can I do that?
No, you cannot do that: the closest you can get is a Dictionary<string,object> (you can replace the object with some other type). Using this dictionary you would be able to create associations between strings (known as "keys") and values stored in the dictionary.
IDictionary<string,object> variables = new Dictionary<string,object>();
string varName = "hello";
variables[varName] = "world";
Console.WriteLine("Name: {0} Value: {1}", varName, variables[varName]);
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
how to check if a function argument is of type integer in c# i.e if I have a variable for example, I need a method to check that the value is an integer value. the method return true if it is an integer and if the value is equal to a double value then method returns false.
This is what you are looking for:
public static bool TryParse(
string s,
out int result
)
Here is an example of the implementation:
string userInput = "4";
int convertedInput;
if(Int32.TryParse(userInput, out convertedInput) {
//the userInput was a valid integer. convertedInput is now set to the integer equivalent of "4"
}
else {
//the userInput was ***not*** a valid integer.
}
Here is the MSDN documentation:
Int32.TryParse Method (String, Int32)
Check these methods out, it might suit your needs:
http://msdn.microsoft.com/en-us/library/system.double.tryparse.aspx
and
http://msdn.microsoft.com/en-us/library/system.int32.tryparse.aspx
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
How can I do the following in C# :
var re = /^\d{4}(\/\d{2}){2} \d{2}(:\d{2}){2}$/;
re.test('2013/03/05 15:22:00'); // returns true
You can use the Regex.IsMatch instead (docs).
Regex.IsMatch("2013/03/05 15:22:00", #"^\d{4}(\/\d{2}){2} \d{2}(:\d{2}){2}$"); // true if match
The below code should get you where you want to be.
Regex rx = new Regex(#"^\d{4}(\/\d{2}){2} \d{2}(:\d{2}){2}$");
String test = "2013/03/05 15:22:00";
if (rx.IsMatch(test))
{
//Test String matches
}
else
{
//Test String does not match
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
How to replace between two characters in a string based on their Unicode code point ?? Could any help please ??Many Thanks.
For example,
Replace (U0041 with U0066)
Use the \u escape code to write the characters:
str = str.Replace('\u0041', '\u0066');
Alternatively, convert the numbers into characters:
int char1 = 65;
int char2 = 102;
str = str.Replace((char)char1, (char)char2);
You can do it like this:
Console.WriteLine("ABC".Replace("\u0041", "\u0066"));
This produces the output fBC, because the unicode code point of u0041 (which is A) has been replaced with the code point of u0066 - an f.