Browsing 7239 questions and answers with Jon Skeet

create object intelligently with java

I am programming with android application, but the method I create view is so tedious, anyone have good idea with them? MapView mMapView1 = new MapView(getActivity(),1); ...
Jon Skeet
people
quotationmark

That looks very much like you could do with an array or a list: List<MapView> mapViews = new ArrayList<>(); for (int i = 1; i <= 6; i++) { MapView mapView = new MapView(getActivity(), i); initialMapView(mapView); ... more 1/21/2014 8:46:24 PM

people

Converting between Int32 and enum

I have a custom type called ScaleGroup. I am trying to parse out the data (done) then convert it to ScaleGroup for comparison. ScaleGroup is an enum. I found this method online of...
Jon Skeet
people
quotationmark

Now that we know that ScaleGroup isn't a class, but an enum, it's simple: int num = (int) ld.ScaleGroup; int secondDigit = num % 10; ld.ScaleGroup = (ScaleGroup) secondDigit; (It's not clear to me that that's actually what you want,... more 1/21/2014 7:17:55 PM

people

How to get Current Quarter from Current Date using C#

I am trying to get the current quarter from current date and store it as int first, then after i get the current quarter like say it is Q1 then i want to store Q1 as string. I am...
Jon Skeet
people
quotationmark

Well you're not specifying "the current date" anywhere - you haven't assigned a value to your dt variable, which is what the compiler's complaining about. You can use: DateTime dt = DateTime.Today; Note that that will use the system... more 1/21/2014 7:03:58 PM

people

How Protected Class will behave in c#

I can understand how protected modifier will work for class members(methods and variables), but anyone please tell me how Protected class will behave. eg:- namespace AssemblyA ...
Jon Skeet
people
quotationmark

It will fail to compile, the way you've written it. Only nested classes can be protected - and they're accessible to any classes derived from the outer class, just like other protected members. class Outer { protected class Nested ... more 1/21/2014 5:12:32 PM

people

Unexacte parsing in SimpleDateFormat

How to parse a string with always different formats of date (sometimes "yyyy-MM-dd HH:mm:ss", or "yyyy-MM-dd'T'HH:mm" or also "yyyy-MM-dd HH:mm")? If I use the following code -...
Jon Skeet
people
quotationmark

I would suggest you just try to parse each specific format, catching ParseException and just moving onto the next format: private static final String[] patterns = { "yyyy-MM-dd HH:mm", "yyyy-MM-dd'T'HH:mm", "yyyy-MM-dd... more 1/21/2014 5:00:27 PM

people

Division by 0.9 c# always returns 0

I'm trying to do a simple picee of maths where I work out if a value is between two values and if so, it does, it should do a simple division. However sometimes the value divided...
Jon Skeet
people
quotationmark

My guess is that the type of m_LocationSqrMtr is int, in which case this expression: 700 / m_LocationSqrMtr ... will be computed using integer arithmetic, and the result converted to float. I suspect you want: if (m_LocationCosts >... more 1/21/2014 3:15:44 PM

people

.Net 4.0 Optimized code for refactoring existing "if" conditions and "is" operator

I have following C# code. It works fine; but the GetDestination() method is cluttered with multiple if conditions by using is operator. In .Net 4.0 (or greater) what is the best...
Jon Skeet
people
quotationmark

Here's one option: private static readonly Dictionary<Type, string> DestinationsByType = new Dictionary<Type, string> { { typeof(Manager), @"\ManagerHome" }, { typeof(Accountant), @"\AccountantHome" }, //... more 1/21/2014 3:02:09 PM

people

Error declaration or range of a variable

I am a beginner in vb.net, recently, I have written this query : I don't think that explain you the goal of my procedure is important (if it is, do not hesitate to tell me.) I...
Jon Skeet
people
quotationmark

Your question is tricky to understand, but I suspect you just need to use r (the row in the current iteration) instead of Row1. The name Row1 only has any meaning within the query expression itself. So try this: Dim req2 = From Row2 In... more 1/21/2014 2:30:36 PM

people

Does working with primitives in Java create new Objects?

AFAIK the following code... void foo () { Integer i1 = new Integer(2); Integer i2 = new Integer(2); Integer i3 = new Integer(2); i3 = i1 + i2; } ... will actually create a...
Jon Skeet
people
quotationmark

Your terminology is a bit confused.... the value of i3 isn't an address (or reference) at all, it's just the integer value. But no, the example you've given won't create any Integer objects. more 1/21/2014 2:19:24 PM

people

Liberal date/time parsing in Pig

(Related to Liberal date/time parsing in Joda-Time) Hey, We're dealing with a pig column that contains mixed date formats: for some records its 09/11/2004 00:00:00, and for some...
Jon Skeet
people
quotationmark

You can use DateTimeFormatterBuilder to achieve this with an optional part: import org.joda.time.format.*; class Test { private static final DateTimeFormatter formatter = new DateTimeFormatterBuilder() ... more 1/21/2014 1:32:09 PM

people