Browsing 7239 questions and answers with Jon Skeet

Cannot access string variable assigned in Using() statement c# wp8

I am trying to access a string outside the using statement whose value is assigned inside a using statement as shown below. I get an error "Use of unassigned local variable...
Jon Skeet
people
quotationmark

Well yes - if iso.FileExists(string.Format("{0}.jpeg", ld.Title)) returns false then you won't be assigning a value to savedUrl. What value do you want savedUrl to have in that case? This has nothing to do with the using statement - it's... more 10/30/2013 6:59:05 AM

people

How to get a return value from a method when the method contains multiple if statements with multiple returns?

public static double changeToSpeed(String time, int distance) { if(time.indexOf(":") == 1){ int minutes = time.charAt(0); String sec = time.substring(3, 7); double...
Jon Skeet
people
quotationmark

The problem at the moment is that your method doesn't return anything if time.indexOf(":") doesn't return 1, 2 or -1. What do you want to do in that situation? You may want to throw an exception, for example. You should work out what you... more 10/30/2013 6:49:40 AM

people

Convert UTC time in brazil time using noda time in mvc4

I am working in MVC4 project .In this project i need to convert UTC time ,which i am getting from server to brazil time zone. How can i convert UTC time to brazil time in noda...
Jon Skeet
people
quotationmark

Fundamentally, if you can get the value as an Instant to start with, it's as simple as: var instant = ...; // However you're receiving that var zone = DateTimeZoneProviders.Tzdb["America/Sao_Paulo"]; var inBrazil = instant.InZone(zone); more 10/29/2013 11:41:44 PM

people

Split a date range into several ranges?

I have a start date and an end date (in sql server datetime format). I want to split this into several ranges ie several pairs of start and end date values. NOTE - I have .NET 3.5...
Jon Skeet
people
quotationmark

You're trying to use System.Tuple<T1, T2>, which was only introduced in .NET 4. You're using .NET 3.5, so that structure isn't available. I suggest you create your own DateRange type which encapsulates a start and end DateTime, then... more 10/29/2013 9:28:08 PM

people

Which button has clicked. Java,Netbeans

I make an app in java with Netbeans. At a Jframe Form,I use four buttons. I need to know which of them has clicked by user. Everyone who can help me? Thanks public class Color...
Jon Skeet
people
quotationmark

You can call getSource on the ActionEvent to find out the source of the event. That will be one of the buttons. more 10/29/2013 9:25:44 PM

people

Why is the following method incorrect in Java?

When I typed in the following method and compiled it in Java, I got "error: unreachable statement", why ? String getRankChar(int rank,boolean isFront) { switch (rank) ...
Jon Skeet
people
quotationmark

You've got a break statement after each return statement. All those break statements are unreachable, precisely because you return before each of them. As per section 14.21 of the JLS: It is a compile-time error if a statement cannot... more 10/29/2013 9:11:06 PM

people

Compilation issues from the command line

I am trying to run everything from the linux command line to which I am relatively new too. I am trying to compile a class which uses some external libraries and when i do javac...
Jon Skeet
people
quotationmark

It's not the code you're compiling that's the problem - it's the code you're compiling against, in pi4j-core.jar, which appears to have been built with Java 7. I strongly suggest you upgrade the JDK, basically. Either that, or: Find a... more 10/29/2013 8:30:41 PM

people

`WEEKDAY` function gives the wrong value?

I am in London GMT Time Zone. If I plug into my excel: =IF(OR(WEEKDAY(F20)=6;WEEKDAY(F20)=7);TRUE;FALSE) I get TRUE back which is clearly wrong because it is a Friday in my...
Jon Skeet
people
quotationmark

WEEKDAY(F20) will be 6 - which is Friday. From the documentation: The day is given as an integer, ranging from 1 (Sunday) to 7 (Saturday), by default. So 6 is a Friday. It looks like you should be checking whether WEEKDAY(F20) is 1... more 10/29/2013 8:21:37 PM

people

Linq to aggregate data across two dictionaries

I'm struggling with some linq to accomplish the following: Dict1 1 0 2 0 3 1 4 1 5 2 6 2 7 2 Dict2 1 45 2 30 3 31 4 43 5 20 6 ...
Jon Skeet
people
quotationmark

It sounds like you're effectively grouping by the value in dictionary 1. I suspect you want something like: var sums = from p1 in dict1 where p1.Value != 0 join p2 in dict2 on p1.Key equals p2.Key ... more 10/29/2013 7:19:57 PM

people

How to format this string so that it can be recognized by Convert.ToDateTime?

I am given this whole string from database: CCC_0293170118-10-2013-20-27-54.541 I had the substring so that I get 18-10-2013-20-27-54, but it throws an error I want to convert...
Jon Skeet
people
quotationmark

A DateTime doesn't have a format. It's just a value. To parse a value such as "18-10-2013-20-27-54" you should use DateTime.ParseExact (or DateTime.TryParseExact, if it's somewhat-expected that the data may be invalid). So something... more 10/29/2013 6:11:38 PM

people