Browsing 7239 questions and answers with Jon Skeet

Converting byte array to pdf throws error when opening the dcoument

I am developing a WCF service that downloads a pdf file from a internet portal converts it into byte array and sends it to the client. On client side i am converting this byte...
Jon Skeet
people
quotationmark

I strongly suspect this is the problem: byte[] Bytes = new byte[Convert.ToInt32(fileSize)]; fileInfo.Stream.Read(Bytes, 0, Bytes.Length); You're assuming a single call to Read will read everything. Instead, you should loop round until... more 11/30/2015 9:58:06 AM

people

The unknown size of array

In Java, I am trying to read files and then I want to put them in an array. But when I declare an array, an error occurs because of unknown length. Here's an example: Object...
Jon Skeet
people
quotationmark

I can work with arraylist for this problem but is there a way that works with arrays ? Only by reproducing the logic of ArrayList, basically. No, there's no way of getting a variable-length array. Arrays in Java just don't support... more 11/30/2015 7:12:49 AM

people

tzset and daylight global variable interpretation in time.h

In the time.h header for the daylight global variable it says: "This variable has a nonzero value if Daylight Saving Time rules apply. A nonzero value does not necessarily mean...
Jon Skeet
people
quotationmark

Australia/Brisbane doesn't use daylight saving time at the moment, but it has in the past; look at the australasia file you'll see the few years where it has observed DST. My interpretation of daylight is that it indicates whether that... more 11/30/2015 6:49:00 AM

people

Value added to array is NULL?

In my code below, I am experiencing a problem I am unable to get around... when I add a class Person object to an array, it appears to add fine, however when I attempt to print...
Jon Skeet
people
quotationmark

No, it hasn't added null to the array. It's put a reference to a Person object in the array, and when you call toString() on that Person object, it's returning the value of the name field... which is always null, because of this... more 11/29/2015 3:30:20 PM

people

Timezone America/Montevideo

If I compute the current local time in Montevideo with the following code: var dt = new Date().toLocaleString("en-US", {timeZone: "America/Montevideo"}) console.log(dt); I...
Jon Skeet
people
quotationmark

The time zone rules for Uruguay changed in release 2015f of the IANA time zone data, which is probably what the web site is using - but I suspect your browser is still using relatively old time zone data. Relevant rules in 2015e: Rule ... more 11/29/2015 12:07:47 PM

people

add object to list with properties at same time

I have, List<Items> itemDetails = new List<Item>(); itemDetails.Add(new Item { isNew = true, Description = "test description" }); Why i can't write above code like...
Jon Skeet
people
quotationmark

When you call Add, that has a void return type... which is why you're getting the error. The overall result of the expression new List<Item>().Add(...) is void. However, you can use a collection initializer: List<Item>... more 11/28/2015 9:34:00 AM

people

C#: Code Optimization for Date Formatting

Using C#, I am trying to populate a variable with a known filename + date. The catch is that the date must always be the last day of the previous month. It must also have no...
Jon Skeet
people
quotationmark

Sounds like you want something more like: // Warning: you should think about time zones... DateTime today = DateTime.Today; DateTime startOfMonth = new DateTime(today.Year, today.Month, 1); DateTime endOfPreviousMonth =... more 11/27/2015 9:41:21 PM

people

+= operator for Delegate

I know that the += operator will add a method to the invocation list maintained by the Delegate base object, for example using System; class Program { delegate void...
Jon Skeet
people
quotationmark

It's not an operator on the delegate type itself, in IL terms - it's defined in the language specification, but you wouldn't find it using reflection. The compiler turns it into a call to Delegate.Combine. The reverse operation, using - or... more 11/27/2015 9:26:19 PM

people

How to count a division of a second, in C#?

I am calculating a timecode feature in my programme. For this I need hours, minutes, seconds and an extra value that ticks 24 times per second. My hours, minutes, seconds...
Jon Skeet
people
quotationmark

It sounds like you just want DateTime.Millisecond and then perform some arithmetic. However: You should only call DateTime.Now once, to avoid getting different values from different calls, leading to a very odd display There's no need... more 11/27/2015 4:02:36 PM

people

Ambiguous behaviour while returning reference value

I have a piece of code: using System; public class Program { private static int Incr(ref int i) { return i++; } public static void Main() { ...
Jon Skeet
people
quotationmark

Think of i += Incr(ref i) as i = i + Incr(ref i); In other words: Evaluate i Call Incr(ref i) Add the two operands together Assign to i Now Incr(ref i) sets i to 1, but returns 0... so the sum ends up being 0 + 0, which is then... more 11/27/2015 11:15:55 AM

people