Browsing 7239 questions and answers with Jon Skeet

If an object is of specified Type, can it still be null?

If you check an object for its type and find out it is of the type you checked for, and you convert it to this type, can this type still be null after conversion ? The code...
Jon Skeet
people
quotationmark

If tx.Tag doesn't change its value, that's fine - but presumably the code quality scanner doesn't know that. It's generally better to use as for this, so that you only evaluate the property once, only perform the type test once, and then... more 9/8/2015 12:30:05 PM

people

LINQ select query with Anonymous type and user Defined type

Anonymous class has read only properties in c#. Which is often used to to declare in linq select query to get particular values from database. In my code I have the following...
Jon Skeet
people
quotationmark

The error you're getting really doesn't have anything to do with LINQ. You can see the same thing without using LINQ at all: var anonymous = new { Name = "Fred" }; anonymous.Name = "Joe"; // Error, as properties of anonymous types are... more 9/8/2015 6:39:11 AM

people

MySQL EST timestamp filed showing 1 hour difference in php

When I run this SELECT DATE_FORMAT(NOW(),'%Y-%m-%d %r') in mysql its showing 2015-09-08 01:47:06 AM. My MySQL system timezone is EDT. However when I run this in PHP in same time...
Jon Skeet
people
quotationmark

You're setting the time zone as EST - that's Eastern Standard Time, which is UTC-5 all year round. If you actually want "Eastern Time", use America/New_York as your time zone identifier. That will vary between EST and EDT at the... more 9/8/2015 6:03:04 AM

people

Why is the bitwise OR operator ( | ) used when catching multiple exceptions in Java?

I've just learned that | is used to catch multiple exceptions in the same block; | is the bitwise operator for OR. In this case, is it still used as a bitwise operator or does it...
Jon Skeet
people
quotationmark

In this case, is it still used as a bitwise operator or does it have a different meaning when in context? It has a different meaning - although it's of the same "flavour" in that it's "if exception X is caught, or exception Y is... more 9/7/2015 6:48:15 PM

people

Java Packages/Library Functions

I am trying to create a package of library functions for a main Java program but I am have some issues. I don't know much about about Java packages and I am going through some...
Jon Skeet
people
quotationmark

You've used -d which says where to put the output, but you haven't told it that the same directory should also be used for input on the classpath. Use the -cp option for that: javac -d classes -cp classes Program.java (It's not clear... more 9/7/2015 1:58:16 PM

people

C# Trying to subscribe to an event in Unity

I'm using the Kinect v2 with Unity3D. A class BodyFramReader has an event Framearrived that I wish to subscribe to. Heres my code so far.. void Start() { ...
Jon Skeet
people
quotationmark

Your sender parameter doesn't match the parameter in EventHandler<TEventArgs> - it should be of type object: void FrameIn(object sender, BodyFrameArrivedEventArgs e) If you need the sender as a BodyFrameReader, you can cast to it... more 9/7/2015 11:50:23 AM

people

FutureTask.get method is blocking forever, although I am setting it's value from another thread

I am trying to signal between two threads using the below FutureResult class which extends FutureTask class. When run the script, it prints the following result. SENDING: 0 ...
Jon Skeet
people
quotationmark

This is the problem: queue.offer(new FutureResult()); You're setting the value on one FutureResult, but that's not the one you're waiting for. Just change that line to: queue.offer(result); and it works fine. more 9/6/2015 6:26:32 AM

people

Java using instanceof method on primitive type gives compiler error

I am learning Java, and I do not understand why the following code does not compile without error: public class SecondClass{ public static void main(String[] args){ int...
Jon Skeet
people
quotationmark

From section 15.20.2 of the JLS: The type of the RelationalExpression operand of the instanceof operator must be a reference type or the null type; otherwise, a compile-time error occurs. In your case, the case of the... more 9/5/2015 9:09:43 PM

people

xmlnodelist to a list of objects in C#

I am reading an xml file using xmldocument. I extracted the nodes of xml using xmlnodelist. I would like to now assign the xmlnodelist to a list of objects "Project". Please let...
Jon Skeet
people
quotationmark

As I noted in a comment, you can do this trivially in LINQ to XML: var projects = XDocument .Load(Server.MapPath("~/Content/abc.xml")) .Root .Elements("Project") .Select(p => new Project { Id = (string)... more 9/5/2015 8:24:41 PM

people

HttpRequest.UrlReferrer does not appear to exist

I have a web application which uses MVC4, but now realised it really should be a Web API and as such I'm moving over to a ASP.NET 4.5.2 web API 2 project. The problem is, where I...
Jon Skeet
people
quotationmark

I suspect you just need to get the current request in a different way, due to being in a static method rather than in a context where you can refer to a Request instance property: var request = HttpContext.Current; var referrer =... more 9/5/2015 8:08:28 AM

people