Browsing 7239 questions and answers with Jon Skeet

Can't figure out where these C# and Java code differ

I have some C# code that converts an image to base64 string. The code is : MemoryStream ms = new MemoryStream(); Image img = Image.FromFile(filename); img.Save(ms,...
Jon Skeet
people
quotationmark

this two piece of code should return the same string for the same image file No, they really shouldn't. The C# code is returning the base64 representation of a JPEG-encoded version of the image data - and potentially some 0s at the... more 2/26/2014 9:10:05 AM

people

async Task<IEnumerable<T>> throws "is not an iterator interface type" error

The following code is throwing is not an iterator interface type only when I use async await and wrap the IEnumerable with Task. If I remove async await, I can go with...
Jon Skeet
people
quotationmark

Only methods declaring that they return IEnumerable<T>, IEnumerable, IEnumerator or IEnumerator<T> can be implemented with iterator blocks. That rules out all async methods. Fundamentally it's not clear how they'd work anyway,... more 2/26/2014 8:57:47 AM

people

Java Recursive functions, single initialization of value

I want to use a recursive function to achieve some stuff, which includes printing output. I want to give increasing levels of tab in the output being printed. I was able to...
Jon Skeet
people
quotationmark

I would split it into two methods: one public one with just the "natural" parameters, and one private one with two parameters (in this case n and count), passing in the initial value. You won't need to modify count within the method - just... more 2/26/2014 7:27:19 AM

people

Class as return value in method?

How do you create the return of a method that has the return type as the class? This is a method to find the sum of two numbers. The number object is created in another class, and...
Jon Skeet
people
quotationmark

How do you create the return of a method that has the return type as the class? The same way you handle any other use of a reference. In your case you could just change your code to: return this; However, that's adding the given... more 2/26/2014 7:07:19 AM

people

C# WPF Time Until xx

I am trying to display the time remaining until a time specified by the user. I want to show Hours, Minutes, Seconds, and maybe milliseconds until the specified time. DateTime...
Jon Skeet
people
quotationmark

If I understand the question correctly, you just want: DateTime target = new DateTime(2014, 2, 24, 18, 0, 0); TimeSpan remaining = target - DateTime.Now; There's no need to parse a string just to get a DateTime value, if you already... more 2/25/2014 7:36:30 PM

people

Read response header from WebClient in C#

I'm trying to create my first windows client (and this is my fist post her), there shall communicate with a "web services", but i have some trouble to read the response header...
Jon Skeet
people
quotationmark

If you want to see the full response, I suggest you use WebRequest/WebResponse instead of WebClient. That's a more low-level API - WebClient is meant to make very simple tasks (such as downloading the body of a response as a string)... more 2/25/2014 7:31:17 PM

people

Dead Code Error in Java

I have an array of objects. I want scan it and as long as the object I find is not null, increase a counter by 1. When I find the first null object, I want to jumb out of the for...
Jon Skeet
people
quotationmark

You're unconditionally breaking out of the for loop at the end of the first iteration of the for loop. That has nothing to do with "when the first null object is found" - it's just at the end of the body of the loop. Additionally, your... more 2/25/2014 6:15:56 PM

people

asp.net calendar is too slow on OnDayRender

I have a calendar in my asp.net application. OnDayRender I need to bind a value for each specific day from the database. So, I establish a connection to the db for each day....
Jon Skeet
people
quotationmark

Instead of doing the database query in OnDayRender, do it when your form initially loads, and fetch the data for the whole month (or whatever the range of the calendar is) into a List or something similar. Then your OnDayRender code can... more 2/25/2014 4:57:25 PM

people

Accesing constructor's base class properties

In order to use a C1DropDownControl inside a C1InputPanel I need to define a class that inherits from the InputControlHost class and then invoke the desired control's constructor,...
Jon Skeet
people
quotationmark

You can just use the Control property and then cast: var control = (C1DropDownControl) controlHost.Control; // Use the various properties more 2/25/2014 2:11:02 PM

people

BufferedInputStream to ByteArrayOutputStream very slow

I have a problem very similar to the link below: PDF to byte array and vice versa The main difference being I am trying to interpret a Socket connection via a ServerSocket...
Jon Skeet
people
quotationmark

Well you're reading until the socket is closed, basically - that's when read will return -1. So my guess is that the other end of the connection is holding it open for 90 seconds before closing it. Fix that, and you'll fix your problem. more 2/25/2014 12:03:32 PM

people