Tags "tostring" Result

Nullable ToString()

I see everywhere constructions like: int? myVar = null; string test = myVar.HasValue ? myVar.Value.ToString() : string.Empty; Why not use simply: string test = myVar.ToString(); Isn't that exactly the same ? At least Reflector says that: public override string ToString() { if (!this.HasValue) { return ""; } return this.valu

it1352 1 2019-05-10

Automatic .ToString()?

I have a method like this: void m1(string str) and have a class like this: public class MyClass { public bool b1 { set; get; } //and other properties } Now why following code does not cause compile error? IClass2 _class2 = new Class2(); MyClass c1 = new MyClass(); _class2.m1("abcdef" c1); When I debug it, I realized that c1.ToStrin

it1352 0 2019-05-06

toString method

I want to add a toString method in the Item class that returns the title of the item in there. I have need make sure that the toString method in the DVD class calls the toString method in Item so that it can return a string that contains both the title and the director. Item is the superclass and DVD is the subclass. public class Item {

it1352 1 2019-05-22

override .ToString()

I would like to override the .ToString() function so that whenever I get a double it outputs only 5 digits after the decimal point. How do I reffer to the object the .ToString is working on, inside the override function? In other words what shell I put instead of the XXX in the following code? public override string ToString() { if (XXX.GetTy

it1352 0 2019-05-10

ToString("0") versus ToString(CultureInfo.InvariantCulture)

I would like to make sure that certain numbers in my application are printed without any separators, groupings etc. no matter what the current environment is. It seems that the following two methods produce the same results (there are possibly more): 123456789.ToString("0"); 123456789.ToString(CultureInfo.InvariantCulture); Are you aware of any

it1352 0 2019-05-06

(String) or .toString()?

I have a method with an Object o parameter. In this method, I exactly know there is a String in "o" which is not null. There is no need to check, or do something else. I have to treat it exactly like a String object. Just curious - what is cheaper - cast it to String, or use Object.toString()? Or is it same by time-/cpu-/mem- price? Update: The

it1352 0 2019-05-13

EditText.getText().toString() crashes

In my android application , I have 3 dialogue boxes in which the user puts info into 3 editTexts and it will display the one of the data onto another class/page after it randomly picks which data to choose. This is my mainClass public class MainActivity extends Activity { //Variables are displayed in this area String choices[] = new Str

it1352 2 2019-05-07

java.util.UUID.randomUUID().toString() length

Does java.util.UUID.randomUUID().toString() length always equal to 36? I was not able to find info on that. Here it is said only the following: public static UUID randomUUID() Static factory to retrieve a type 4 (pseudo randomly generated) UUID. The UUID is generated using a cryptographically strong pseudo random number generator. Returns

it1352 0 2020-07-04

ToString() returns null?

I am trying to determine cause of 'Null reference exception' on published remote site. So, I can't debug it directly and can operate only with logs. So my question is: Is it possible, that .ToString() method of any of built-in .NET types returns null? EDIT: I suspect DateTime.ToString(invariantCulture) method with badly constructed culture setti

it1352 0 2019-05-06

context.Response.Charset = Encoding.UTF8.ToString();

I had used this in my code to set the Charset but IE did not like it. Any reason why? context.Response.Charset = Encoding.UTF8.ToString(); I ended up having to set it to just context.Response.ContentType = "application/json;charset=utf-8" or context.Response.Charset = "utf-8"; instead. Not sure then what Encoding.UTF8.ToString(); would be uti

it1352 0 2019-05-08