Browsing 7239 questions and answers with Jon Skeet

Java type promotion with "expressions"

Can the variable below (called b) be called an expression, if it is the only thing located to right of the equals sign? // This code fragment will not compile. // c is a char,...
Jon Skeet
people
quotationmark

Can the variable below (called b) be called an expression, if it is the only thing located to right of the equals sign? Yes, absolutely. I understand that Java promotes all bytes to ints. Well, in some cases. Not in all... more 11/1/2013 9:05:10 AM

people

Why HttpListener couldn't start?

I am designing a http server using .NET. I basically use HttpListener to get http request from client. At the beginning, I have to specify the URL, and add that URL to...
Jon Skeet
people
quotationmark

I can think of two simple reasons this might be happening: You have something else which is already listening on port 80 (such as IIS) You don't have permission to listen on port 80 The exception should indicate which of these is the... more 11/1/2013 6:57:28 AM

people

TextBlock insists on showing " instead of " in metro app

I'm trying to get a Text description from a website and used this code HttpResponseMessage response1 = await httpClient.GetAsync(url); ...
Jon Skeet
people
quotationmark

You're calling Replace but not doing anything with the result - strings are immutable in C#, so the Replace method doesn't change the contents of the existing string. As the documentation states: This method does not modify the value... more 11/1/2013 6:52:53 AM

people

Mocked method not called in Mockito

Hello I have one service with a method: @Service public class CaptchaServiceImpl implements CaptchaService { @Autowired private MessageSource messageSource; @Override public...
Jon Skeet
people
quotationmark

This is the problem: ReCaptchaImpl reCaptcha = new ReCaptchaImpl(); That's just creating a new instance - your mock isn't being used at all. Note how you're not passing your mock into anything - how did you expect the production code to... more 10/31/2013 9:45:41 PM

people

Accessing and saving XElements in an object collection

I Have the following scenario, and would like some help guidance on the topic: I Have an XML file composed of user credentials (Not for commercial use, so security is really not...
Jon Skeet
people
quotationmark

You just need to call the ToList extension method to create a list. Also, you need to create Credentials objects rather than instances of an anonymous type. For example: var xmlResults = from element in Root.Elements().Elements() ... more 10/31/2013 8:04:23 PM

people

Object creation for nested data structures, an avoidable hit on performance?

From Android's Performance Tips: Object creation is never free. ... As you allocate more objects in your app, you will force a periodic garbage collection, creating little...
Jon Skeet
people
quotationmark

Could I re-use the inner objects that turn out to be useful in the next round of GPS Data collection, and let any remaining inner objects be garbage collected? Yes, potentially. But do you have any indication that it's actually a good... more 10/31/2013 7:20:35 PM

people

System.String ToString() error on a database call using c#

I'm running into a snag with some code of mine. I have a controller in which I calling to retrieve a company list from my database. However, when I test it I get an error stating...
Jon Skeet
people
quotationmark

LINQ to SQL doesn't know how to translate ToString() into SQL in this case. The simplest solution is to use AsEnumerable to "transfer control" to LINQ to Objects. You can use an initial Select to make sure you only pull the relevant... more 10/31/2013 7:15:04 PM

people

join not returning all elements in left table C# lambda

I have 2 tables, the left table has data like this: I do a left join with another table with the following expression: var result = posicion.Join(fact, ...
Jon Skeet
people
quotationmark

what would be missing from my join? Presumably there are no entries in fact which have the corresponding Cod_articulo values (e.g. 60155 for posicion 3). Join in LINQ represents an inner join, where there has to be an entry in both... more 10/31/2013 3:12:14 PM

people

Convert an array of chars to an array of integers

I have these arrays char[] array = {'1', '2', '3', '4'}; int[] sequence = new int[array.Length]; Is there an easy way to assign the numbers in array to sequence? I tried...
Jon Skeet
people
quotationmark

If you convert each character to a string first, then use int.Parse (or still Convert.ToInt32) that will work. Personally I'd use LINQ for this, e.g. int[] sequence = array.Select(x => int.Parse(x.ToString())).ToArray(); ... or use... more 10/31/2013 1:45:27 PM

people

TryParse in one line: accepted challenge?

Just a challenge I guess, but I hope to use TryParse in just one line :) My code: DateTime tempDate; user.DataNascita = DateTime.TryParse(txtDataDiNascita.Text, out tempDate) ?...
Jon Skeet
people
quotationmark

You'd need a helper method, basically. For example: public static DateTime? TryParseDateTime(string text) { DateTime validDate; return DateTime.TryParse(text, out validDate) ? validDate : (DateTime?) null; } Then you can just... more 10/31/2013 9:54:36 AM

people