Browsing 7239 questions and answers with Jon Skeet

Why last array filled with first array without asking?

I try to hold some value in 1st array, then another value in 2nd array, I try to print 1st array and it returns 2nd array values. Any ideas why ? this is main method to call...
Jon Skeet
people
quotationmark

You're only actually populating a single array - and overwriting it every time you call getCol. So the values of cola1 and cola2 end up referring to the same array, whereas you want them to refer to different arrays. You should probably... more 6/21/2014 12:52:56 PM

people

What is the Time format for this "date": "2014 08 20 00:00:00 0500"?

I tried converting this date the following way: SimpleDateFormat fromFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSSZ"); but I got: java.text.ParseException:...
Jon Skeet
people
quotationmark

That "-0500" is the offset from UTC, in RFC822 format. You just want Z, without the SSS. The Android SimpleDateFormat docs have it like this in the table: Symbol: Z Meaning: time zone (RFC 822) Kind: (Time Zone) Example: Z/ZZ/ZZZ:-0800... more 6/20/2014 7:26:27 PM

people

How does returning by enable access control? (Java)

In Java, when you make a getter for a private field of class as follows(assume child is an ArrayList): public ArrayList getChild() { return this.child; } you return a...
Jon Skeet
people
quotationmark

you return a reference to the private field "name" Well, not quite. You return the current value of the child field. It's important to understand that that's not the same as somehow returning a reference to the field itself. After the... more 6/20/2014 7:16:43 PM

people

Java: Conditional Operator differs from if/else

why does the conditional operator return 2.0 and the if/else block returns 2 in the following example? I am kind of confused because these two blocks should be...
Jon Skeet
people
quotationmark

The same branch is being taken in both cases. You can verify that by using very different answers for the different branches: if (value == Math.floor(value)) { result = ((int) value * 100); } else { result = value; } and result... more 6/20/2014 6:46:44 PM

people

How do I create a bunch of tasks in a loop

I have a list of 100 values I want to spawn 5 threads to process 20 each my code is basically for (int i = 0; i<5; i++) { Task.Run(() => { ...
Jon Skeet
people
quotationmark

You're nearly there, but as well as creating a copy of the local variable, you need to use it in your lambda expression: for (int i = 0; i < 5; i++) { int localCopy = i; Task.Run(() => { myMethod(myList.Skip(localCopy *... more 6/20/2014 4:15:20 PM

people

Mockito Matcher parameters showing as undefined

I am trying to Mock a method contained in the Main class of an application. I'd like to test that when all parameters are submitted successfully, the application calls the correct...
Jon Skeet
people
quotationmark

You should be getting it as a compile-time error, not an exception (unless the actual exception is that you've got an unresolved compile-time error). Just importing org.mockito.Matchers means you can use the name Matchers to mean... more 6/20/2014 3:45:43 PM

people

Get contents of a Var where part of line matches search string C#

I am reading a couple of csv files into var's as follows: var myFullCsv = ReadFile(myFullCsvFilePath); var masterCsv = ReadFile(csvFilePath); Some of the line entries in each...
Jon Skeet
people
quotationmark

Well you could use: var results = myFullCsv.Where(line => line.Split(',')[2] == targetValue) .ToList(); That's just doing the "splitting and checking" you mention in the question but it's pretty simple code. It... more 6/20/2014 3:13:34 PM

people

Can I enforce that fields in a POCO are only ever set in a type initialiser?

If I have a POCO such as this: [Poco] public class MyPoco { public string FirstName { get; set; } public string LastName { get; set; } public string Address { get;...
Jon Skeet
people
quotationmark

I don't know whether you can do this in CQL, although even if you can't, you might well be able to do it with Roslyn. However, you might want to consider using a builder pattern instead: var poco = new MyPoco.Builder { FirstName =... more 6/20/2014 8:27:54 AM

people

Will the scope of floating point variables affect their values?

If we execute the following C# code on a console application, we will get a message as The sums are Not equal. If we execute it after uncommenting the line...
Jon Skeet
people
quotationmark

What is the actual reason for this behaviour? I can't provide details for exactly what's going on in this specific case, but I understand the general problem, and why using Console.WriteLine can change things. As we saw in your... more 6/20/2014 6:48:42 AM

people

C# Clock using Custom Time

Hi I am implementing the simple Clock. My requirement is I want my clock to execute with the time I set, not the System Time. I have implemented using timer but it is not in...
Jon Skeet
people
quotationmark

I would strongly avoid repeatedly adding a particular amount of time - timers aren't going to fire exactly on time, so you'll end up drifting due to that. Instead, remember the difference between the system clock and add that difference... more 6/20/2014 6:05:58 AM

people