Browsing 7239 questions and answers with Jon Skeet

Memory reservation for java objects

I know that when declaring object instances in c++ like so: Object object the Object constructor is called and memory is provided for that object, however i find that when you...
Jon Skeet
people
quotationmark

You need to differentiate between the space required for the variable and the space required for the object. Bear in mind that the value of the variable is just a reference - very much like a pointer in C++. So if you have: Object x =... more 4/14/2015 5:25:09 PM

people

Saving a Wave Stream on local disk after Speech Synthesizing

How do I write the "Hello World! Speech" text as a local disk .wav file? hellospeech.wav remains 0Ko. Where I'm wrong? SpeechSynthesizer synthesizer = new...
Jon Skeet
people
quotationmark

Two problems: You're not rewinding the MemoryStream after saving to it You're calling Speak before you set the output You're also not using using statements - but that's not causing this issue. I haven't used this SDK myself, but I'd... more 4/14/2015 2:25:49 PM

people

Multithreading how to invoke Action

I have some menu popup with action buttons. This is popup so it is made in new thread. I add event to created buttons something like this: private StdProcedure...
Jon Skeet
people
quotationmark

m_ToInvoke() is just C# syntactic sugar for m_ToInvoke.Invoke() m_ToInvoke.Invoke() executes the delegate synchronously, in the same thread m_ToInvoke.BeginInvoke() schedules the delegate for invocation in a thread-pool thread; the... more 4/14/2015 2:12:39 PM

people

Nullable create via reflection with HasValue = false, given a parameter of type `Type` only

Given a type parameter which is a Nullable<>, how can I create an instance of that type which has HasValue = false? In other words, complete this code: //type is...
Jon Skeet
people
quotationmark

Given a type parameter which is a Nullable<>, how can I create an instance of that type which has HasValue = false? If you want a method with a signature of object, you just return null: //type is guaranteed to be implement... more 4/14/2015 12:20:08 PM

people

FileInfo.Length != sum of all line length

I'm trying to make a progress bar for big file's reading. I set the progress bar's maximum value to FileInfo.Length, I read each line using StreamReader.ReadLine and compute the...
Jon Skeet
people
quotationmark

Two problems here: string.Length gives you the number of characters in each string, whereas FileInfo.Length gives you the number of bytes. Those can be very different things, depending on the characters and the encoding used You're not... more 4/14/2015 8:33:03 AM

people

warning CS1570: XML comment on 'myclass' has badly formed XML 'A name was started with an invalid character.'

I have some C# codes using doxygen comments for some equations. VS2013 should me a warning message warning CS1570: XML comment on 'myclass' has badly formed XML -- 'A name was...
Jon Skeet
people
quotationmark

Yes, you need to escape the < - in XML it's &lt;. So this would be valid: /// \f[ /// T_{max}&lt;30 /// \f] Now I don't know how doxygen handles comments in C# - if it really wants the original form, because it's not... more 4/14/2015 7:40:57 AM

people

Outer join two tables with null values

I have this data structure: class Person { public string FirstName { get; set; } } class Pet { public int Id { get; set; } public string Name { get; set; } } class...
Jon Skeet
people
quotationmark

Before the question changed (Originally the link table had a reference to the pet, not an ID.) It looks to me like you only need one join, because you can just use the Pet property from the link, where there is one: var query = from... more 4/14/2015 6:23:36 AM

people

Collection class and IDisposable interface

I've been reading about IDisposable interface lately (this topic was quite useful Proper use of the IDisposable interface) and also about usage of using statement (topic Uses of...
Jon Skeet
people
quotationmark

Or does GC do it automaticly and I shouldn't even bother about it. This. Unless you have unmanaged resources (either directly or by way of a reference to something else which is disposable), you almost certainly shouldn't implement... more 4/13/2015 1:43:41 PM

people

Cannot convert fom enum to interface it implements

I'm in Java 7 and I have the following enum: public enum BooleanEnum implements StringRepresentable{ YES { @Override public String getStringRepresentation()...
Jon Skeet
people
quotationmark

It implements the interface, therefore the code should have compiled fine. No, because the type argument is being inferred as BooleanEnum - and a List<BooleanEnum> isn't a List<StringRepresentation>... you can add... more 4/13/2015 12:11:49 PM

people

Get XMLGregorianCalendar date in EST time Zone

I am using TimeZone.setDefault(TimeZone.getTimeZone("EST")); to get the time zone EST and it is working fine to me. But sometimes I am getting time zone EDT when no one called...
Jon Skeet
people
quotationmark

I suspect you should just pass the time zone to toGregorianCalendar. I'd also strongly recommend using full time zone IDs rather than abbreviations - after all, I suspect you really want Eastern time (EST and EDT) rather than just... more 4/13/2015 8:24:56 AM

people