Browsing 7239 questions and answers with Jon Skeet

Time format with culture specific abbreviated letters

I have an integer number which represents number of minutes. I need to display that number in dd:HH:mm format to user. Converting number of minutes to dd:HH:mm format is not a...
Jon Skeet
people
quotationmark

I don't believe there's anything within the .NET culture information which gives this information, no. If there were, it would be in DateTimeFormatInfo. If (as I suspect) you can't find what you're looking for within the .NET classes, you... more 11/10/2013 9:26:09 PM

people

How restart a thread, no pause nor sleep

I've searched around and I want to abort a thread and restart it, something who should be really simple but no one is answering. Basicly I have an user who conenct throught a...
Jon Skeet
people
quotationmark

I've searched around and I want to abort a thread and restart it, something who should be really simple but no one is answering. You can't - it's as simple as that. Once a thread has been successfully aborted (i.e. it really has... more 11/10/2013 9:23:15 PM

people

Encode byte[] as String

Heyho, I want to convert byte data, which can be anything, to a String. My question is, whether it is "secure" to encode the byte data with UTF-8 for example: String s1 = new...
Jon Skeet
people
quotationmark

You should absolutely use base64 or possibly hex. (Either will work; base64 is more compact but harder for humans to read.) You claim "both variants work perfectly" but that's actually not true. If you use the first approach and data is... more 11/10/2013 8:26:03 PM

people

How do I check if a Guid value is inside a LIST of Structures?

How do I check if a Guid value is inside a LIST of Structures? public struct Info { public Guid EntityTypeID; public String Name; } List<Info> InfoList =...
Jon Skeet
people
quotationmark

I suspect you're looking for Any: ... InfoList.Any(x => x.EntityTypeID == v.EntityTypeItemID) You can't use Contains, because you're looking for something which matches part of the item. (I'd also strongly discourage using public... more 11/10/2013 5:47:48 PM

people

This method must return a result of type int

All is working fine apart from the last method getPrice() I am returning int but I keep getting the same error. Also if I set warranty to be false it still returns...
Jon Skeet
people
quotationmark

The problem is that the compiler won't work out that this: if (hasWarranty == true) { ... } else if (hasWarranty == false) { ... } will always execute exactly one of those paths. It thinks you might get to the end of the if... more 11/10/2013 5:02:18 PM

people

Uploading stream with MD5 hash results in "The Content MD5 you specified was invalid"

I am working on an implementation, using Amazon S3. I use the Amazon C# SDK, and I try to upload a created ZIP file using the putObject method. When I upload the file, I get the...
Jon Skeet
people
quotationmark

I suspect the problem may be that after computing the hash of the stream, the stream is left at the end of the data... so when anything else reads from it later, there'll be no data. Try add this after the call to... more 11/9/2013 3:55:49 PM

people

The cause of java "incompatible types"?

import java.util.*; class Poly{ protected int[] coef = new int[1001]; protected int[] exp = new int[1001]; protected int len; protected void attach(int c, int...
Jon Skeet
people
quotationmark

The problem is that the add method is declared to return Add - but you're trying to assign the return value to a variable of type Mul. That's just not valid. If you change the declared type of sum to Add instead of mul, then that... more 11/9/2013 12:53:10 PM

people

Strange Interlocked behavior in wp7

I have a library, which was basically oriented on wp8. I made new wp7 library and added all code there. There are lots of async/await, so i added: MS Portability pack 1.1.3 MS...
Jon Skeet
people
quotationmark

I assume you mean Interlocked.Add(ref long, long)? If so, the documentation isn't exactly blatant, but it does explain it: Version Notes Silverlight for Windows Phone 64-bit members of the Interlocked class are present but not... more 11/9/2013 12:17:02 PM

people

Can't declare an object in if else. Not visible outside if else clause

When I instantiate the Textwriter object in the if/else clause, it is not visible outside the clause. What can I do here? I want to either append to or write a new file. Here is...
Jon Skeet
people
quotationmark

You can declare it before the if statement, but with no assignment - and then make sure that you assign a value to it in both branches: TextWriter outFile; if (inFile.Peek() == -1 || inFile == null) { outFile =... more 11/9/2013 8:31:28 AM

people

How do i get the array beginning instead the end of it?

This is the code in timer1 tick event: file_indxs = file_indxs - 1; if (file_indxs < 0) { file_indxs = file_array.Length - 1; } file_array.Length - 1 is the end it will...
Jon Skeet
people
quotationmark

I suspect you actually want: fileIndex++; if (fileIndex == fileArray.Length) { fileIndex = 0; } (I've changed the variable names to be more conventional at the same time.) Note the change of condition - if you're incrementing... more 11/8/2013 11:17:36 PM

people