Browsing 7239 questions and answers with Jon Skeet

Difference between await and ContinueWith

Can someone explain if await and ContinueWith are synonymous or not in the following example. I'm trying to use TPL for the first time and have been reading all the documentation,...
Jon Skeet
people
quotationmark

In the second code, you're synchronously waiting for the continuation to complete. In the first version, the method will return to the caller as soon as it hits the first await expression which isn't already completed. They're very... more 9/23/2013 5:26:59 PM

people

append bytes to string in java

I have to deal with ascii structured file, I need to put these two constant bytes to the end of every line so that I can respect the file structure that was gave me: private...
Jon Skeet
people
quotationmark

Just change your constants to be strings instead: private final static String ENDRECORD = "\r"; private final static String ENDLINE = "\n"; Then your existing concatenation should be fine. char would be fine too: private final static... more 9/23/2013 4:56:05 PM

people

Is it a good practice to have parameter that is a global variable?

I am an AP java student and while working on a project I wondered if it is a good practice to have a parameter that is a global variable. If you're wondering why I would want to...
Jon Skeet
people
quotationmark

and every time I pass the arguments to the parameter they will automatically be assigned to the global variables? No. There's nothing within Java which will make the "parameter to instance variable" (which isn't really "global")... more 9/23/2013 3:15:45 PM

people

Concatenating variables which hold integers

Which is the best way to concatinate 2 variables that hold integers ? var var1 = 1; var var2 = 2; console.log(var1 + var2) //result 3; expected 1 2
Jon Skeet
people
quotationmark

Just use string concatenation explicitly by including a string literal: console.log(var1 + " " + var2); Or in a different situation where you didn't want the space, you could use: console.log(var1 + "" + var2); or perform the string... more 9/23/2013 3:12:51 PM

people

XML hidden characters, how to remove Bom

I am trying to create an XML file through code. The file is being created successfully but my system needed for the file only reads UTF-8. The file is not being loaded...
Jon Skeet
people
quotationmark

If all you want is to avoid the creation of a BOM, that's easy - just create a UTF8Encoding which doesn't use one and an XmlWriterSettings with that encoding: var path = Path.Combine(pathDesktop, "\\22CRE002.XPO"); var settings = new... more 9/23/2013 2:47:16 PM

people

XML getting wrong UTF encoding

I am trying to encode my xml text using utf-8 with the code below. For some reason I am getting utf-16 instead of utf-8. Any reason why please? StringWriter writer = new...
Jon Skeet
people
quotationmark

StringWriter itself "advertises" (via the TextWriter.Encoding property) an encoding of UTF-16, so the XmlWriter detects that and modifies the XML declaration accordingly. You are actually writing out the data as UTF-8 - it's just that the... more 9/23/2013 2:33:57 PM

people

Why DateTime.ParseExact(String, String, IFormatProvider) need the IFormatProvider?

If we're using the ParseExact method for exact date-time's parsing using a specified format, why do we need to provide a IFormatProvider object? what is the point behind it? For...
Jon Skeet
people
quotationmark

why do we need to provide a IFormatProvider object? what is the point behind it? It allows for culture-specific options. In particular: The format you use could be a standard date/time format, which means different patterns in... more 9/23/2013 2:15:59 PM

people

I have a java code ,cannot understand interface

Here is the code i have three interfaces interface i1{ int x=1; } interface i2{ int x=2; } interface i3{ int x=3; } class A implements i1,i2,i3{ system.out.println(x); // It...
Jon Skeet
people
quotationmark

How to answer this or how to overcome this problem. Don't use fields in interfaces, or if you must use them, and they must have the same names, just fully qualify them: System.out.println(i3.x); Note that with import static, the... more 9/23/2013 10:20:56 AM

people

JVM running on IDE takes more processing power than running on command line

I faced a very frustrating issue. I used an IDE to develop my application. I was monitoring performance through the execution times in IDE but unfortunately when I exported my...
Jon Skeet
people
quotationmark

(After a conversation in comments.) It seems this is down to a difference in how console output is handled in your command line and in your IDE. These can behave very significantly differently in terms of auto-scrolling, size of buffer... more 9/23/2013 9:57:34 AM

people

yield return in recursion

i am attempting to create an IEnumrable<PropertyInfo> iv'e got a method called Disassemble which iterates recursively throw a given object and all it's child...
Jon Skeet
people
quotationmark

You're calling the method, but then ignoring the results. You may want something like: foreach (var item in childObject.Disassemble<T>()) { yield return item; } I think you're a bit confused about what yield return does - it... more 9/23/2013 7:29:48 AM

people