Browsing 7239 questions and answers with Jon Skeet

null vs default(decimal?) set to null giving different results

Using: Entity Framework 4.3.1, MVC 4 Sample database records (for example): Id Height 1 null 2 2.1 Why does this first statement bring back zero...
Jon Skeet
people
quotationmark

I've certainly seen some odd LINQ behaviour before now, due to the way that SQL handles nulls not being the same as the way that C# handles nulls. In C#, a == b is true if a and b are both null, whereas in SQL they're not... instead you... more 5/10/2016 3:59:46 PM

people

Error occured while using java foreach statements

My code as follows public class Test { public static void main(String[] args) { int count1 = 0, count2 = 0; Test[] test1 = new Test[5]; Test[] test2...
Jon Skeet
people
quotationmark

Changes to the iteration variable in an enhanced-for statement do not affect the underlying collection. So while this modifies the array: test[i] = new Test(); // In for loop ... this doesn't: test = new Test(); // In enhanced for... more 5/10/2016 10:11:32 AM

people

What type of File is created when we create new File without the extension?

In java, when we create a file, we create files using the name of the extension. For example : File file = new File("D:/light.txt"); I would like to know what type of file...
Jon Skeet
people
quotationmark

This answer assumes you're doing more than just creating a File object - that you're actually creating a file on the file system. (A File object is just a logically representation of a file system entry which may or may not exist.) If... more 5/10/2016 6:11:33 AM

people

If Getter/Setter are replaced at compile time in java; how can their purpose be fulfilled?

I'm new to java. I have been reading about Getter/Setter (Why to use getter/setter and getter/setter poor design). While I read on Oracle Understanding JIT. I've two questions as...
Jon Skeet
people
quotationmark

if JIT replaces some getters/setters with actual value while compiling a code how purpose of getter/setter is fulfilled in java particular ? Because it's only an optimization. The getters and setters still work exactly as expected -... more 5/9/2016 7:32:49 AM

people

Ambiguous Overloaded method call resolved

When I call, call('a'); it output "char" and it is fine because char primitive type will take first priority over boxing it to Character. static void call(char i){ ...
Jon Skeet
people
quotationmark

How is call to call('a', 'a'); is ambiguous? Because in order for the (char i, Character j) overload to be applicable, the rules around boxing are brought into play - and at that point both calls are applicable. This is the second... more 5/8/2016 11:26:11 AM

people

What is this java post increment operator doing?

So there's a piece of an radix sort implemented Java code that reads as below: aux[count[a[i]]++] = a[i]; Why use a post increment operator? Why not aux[count[a[i]]+1]? Is the...
Jon Skeet
people
quotationmark

Is the post increment simply to increment the value in count[a[i]] by 1 and store it there? Yes, exactly. There are two side-effects of the statement: one is a modification to an element of aux, and the other is a modification to an... more 5/8/2016 7:18:13 AM

people

Displaying the time in a WPF Window

I'm creating a WPF app and I want a label called SystemTimeLabel to display the time. The time, as in, the time. I want it to display the present time, not just the time by which...
Jon Skeet
people
quotationmark

Sure - you just need to update the label periodically, which can easily be done with a DispatcherTimer. Just register an event to fire periodically - say 10 times per second - and update the label with the system time every time the event... more 5/7/2016 4:21:14 PM

people

How to make a case insensitive list search in C#?

I've been trying to make a list search method where I could present the items in the list unaffected and after a week going through every search method I could find I realizes...
Jon Skeet
people
quotationmark

You could use IndexOf with a case-insensitive comparison: var query = posts.Where( logg => logg.IndexOf(searchKey, StringComparison.CurrentCultureIgnoreCase) != -1); foreach (string result in query) { ... more 5/7/2016 3:44:41 PM

people

linq expressions from simple sql, seems there is limitation in linq

I have following sql query select * from one a inner join one b on ( a.weekday=b.weekday and a.starttime =b.starttime and...
Jon Skeet
people
quotationmark

LINQ only supports equijoins, but you could do an equijoin for the weekday and starttime, and endtime parts and then a where clause for the rest. // Names changed to be more idiomatic where feasible. We have no // idea what "sl"... more 5/7/2016 10:09:30 AM

people

confused when using "using block" C#

I often use the "using" block to dispose the objects. Today, I using HttpWebRequest to post data, and I feel confused between two method. Method 1: var request =...
Jon Skeet
people
quotationmark

Basically, it depends on two things: Whether the StreamWriter constructor will ever throw an exception when passed a non-null Stream reference - and I don't think it will in this case. (If the stream were read-only, it would... at which... more 5/6/2016 4:46:59 PM

people