Browsing 7239 questions and answers with Jon Skeet

ref out default values

I'm still trying to learn and since I don't know many peers who have a good programming knowledge I told myself to start asking more questions about good programming practices if...
Jon Skeet
people
quotationmark

The simplest solution (in terms of changing very little code) would be to have an overload: private float CountAvailability(DateTime startDate, DateTime endDate, string machine) { float ignored1 = 0f, ignored2 = 0f; return... more 10/21/2014 6:04:54 AM

people

Why does ((IList<T>)array).ReadOnly = True but ((IList)array).ReadOnly = False?

I know that in .NET all arrays derive from System.Array and that the System.Array class implements IList, ICollection and IEnumerable. Actual array types also implement...
Jon Skeet
people
quotationmark

This looks like a plain bug to me: It clearly isn't read-only, as the indexer allows it to be modified It is not performing a conversion to any other kind of object Note that you don't need to cast - there's an implicit... more 10/20/2014 9:50:08 PM

people

Why doesn't List.Contains work as I expect?

Why does this program print "not added" while I think it should print "added"? using System; using System.Collections.Generic; class Element { public int id; public...
Jon Skeet
people
quotationmark

The Contains method does not use the == operator‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌ No - it uses Equals, which you haven't overridden... so you're getting the default behaviour of Equals, which is to check for reference... more 10/20/2014 6:39:48 PM

people

Calling overloaded method with generic property calls wrong overload

I have a basic filter class that stores a string parameter name and a generic T value. The filter has a method Write(writer As IWriter) which will write the contents of the...
Jon Skeet
people
quotationmark

The problem is, when I call writer.Write(ParameterName, Value) and T is a string, it calls the overload for string/object, not string/string! Yes, this is expected - or rather, it's behaving as specified. The compiler chooses the... more 10/20/2014 4:35:39 PM

people

Elements removed after execute Comparator in TreeSet

I have this peace of code: final SortedSet<NisType> lAllNNisType = new TreeSet<NisType>(new NisTypeComparator()); lAllNisType.addAll(pAllNisType); // where...
Jon Skeet
people
quotationmark

Yes, this is behaving precisely as documented. Note that the ordering maintained by a sorted set (whether or not an explicit comparator is provided) must be consistent with equals if the sorted set is to correctly implement the Set... more 10/20/2014 3:21:19 PM

people

PHP add one day in period of daylight saving

I am in Brazil and we changed to summer time this saturday. I have a loop that genrates timestamps for midnight for every day in a selected timerange. So I get the timestam of...
Jon Skeet
people
quotationmark

I have a loop that genrates timestamps for midnight for every day in a selected timerange. That's your first problem - assuming that midnight even exists. Whether or not that's true depends on your definition of midnight. In the... more 10/20/2014 2:07:02 PM

people

Logical right shift operator in java

I am beginner to java... I have tried very much but could not find the way the following line System.out.println (-11); gives 2147483647 ? Can anyone help me ?
Jon Skeet
people
quotationmark

>>> is the bitwise right-shift operator, with 0 sign extension - in other words, all bits "incoming" from the left are filled with 0s. -1 is represented by 32 bits which are all 1. When you shift that right by 1 bit with 0 sign... more 10/20/2014 1:55:11 PM

people

Mix Items to new List with Linq

Lets say this is my list {1, 2, 3, 4, 5, 6, 7, 8, 9 } Now I would like to mix the items to following list: { 1, 9, 2, 8, 3, 7, ..} Basically always one item from left side and...
Jon Skeet
people
quotationmark

Yes, you can do this using just LINQ (reasonably briefly, even), but it's not exactly pleasant: Reverse the list Zip it with the original list to get pairs (1, 9), (2, 8) etc Flatten the result Take only the original number So: var... more 10/20/2014 11:50:53 AM

people

Error due to version compatibility in running jar file

I have created a jar file using JDK 8.0 and I tried to run the jar file in a system which is having JRE 7.0, but I am getting an error like this: C:\Users\admin\Desktop>java...
Jon Skeet
people
quotationmark

You need to use the -source option for javac. For example: javac -source 1.7 foo/Bar.java In theory you can specify the source and target options separately, but judging by your comment, it sounds like you can't use Java 8 language... more 10/20/2014 9:33:55 AM

people

What is the [do(args)] notation called in C#?

When we import legacy dlls in C# we use something like the following notation: [DllImport("user32.dll")] // Why am I enclosed in "["s static extern int MessageBoxA(int...
Jon Skeet
people
quotationmark

These are attributes. They're not "preprocessor" parts of the language - unlike things like #if, #pragma (which are still not really handles by a preprocessor, but are meant to be thought of that way). Basically, attributes allow you to... more 10/20/2014 6:02:00 AM

people