Browsing 7239 questions and answers with Jon Skeet

Access a property of IEnumerable

I have a custom class for a combobox having following properties: public IEnumerable<object> ItemsSource { get { return...
Jon Skeet
people
quotationmark

It's not entirely clear why you need to do this binding yourself (when WPF does a lot of this for you), but this might work: foreach (object item in ItemsSource) { var property = item.GetType().GetProperty(DisplayMemberPath); var... more 12/24/2013 10:38:38 AM

people

Compiler error for exhaustive switch

Why do I get a "not all code paths return a value", for VeryBoolToBool() in the following code? public enum VeryBool { VeryTrue, VeryFalse }; public bool VeryBoolToBool(VeryBool...
Jon Skeet
people
quotationmark

Can't the compiler see there are no other options for VeryBool? Nope, because there are. For example, I could call: VeryBoolToBool((VeryBool) 5); Enums in C# are not limited sets of values. They're effectively named numbers, with... more 12/24/2013 10:20:08 AM

people

Determine the internet time of another country in Java

I am developing a Java application that will be used by people from around the world. One feature requires it to display the current time in Melbourne, Australia. I have found...
Jon Skeet
people
quotationmark

You're currently returning a java.util.Date - that doesn't have a time zone. It's just an instant in time. It's not in your time zone, or some other time zone - it's just an instant. When you call toString(), that will give you a textual... more 12/23/2013 12:18:15 PM

people

Why is finalizer called on object

Here is example program that exhibits surprising finalization behavior: class Something { public void DoSomething() { Console.WriteLine("Doing something"); } ...
Jon Skeet
people
quotationmark

I can't reproduce the problem on my laptop, but your DoSomething method doesn't use any fields within the object. That means that the object can be finalized even while DoSomething is running. If you change your code to: class... more 12/22/2013 4:50:48 PM

people

Strange behavior of EOFException

I have some simple class that is DataInputStream stream to read from file. I have surrounded this stream with EOFException try-catch block. It has some strange behavior coz...
Jon Skeet
people
quotationmark

Well, you're getting an EOFException because you're reading forever - you never change the value of done. The reason it's appearing in the middle of the text instead of at the end is that you're using System.err to print in the... more 12/22/2013 10:11:04 AM

people

Property attribute in an interface

i have a property attribute that can be defined once per class, and an empty interface called ISql which i just use to mark my objects that are allowed to use my custom buillt...
Jon Skeet
people
quotationmark

No, attributes aren't part of the contract of the interface, in terms of what implementations must provide. For this sort of thing, I usually just add a unit test which uses reflection to find all implementations and validates it that... more 12/21/2013 11:38:46 AM

people

Custom exception with Guava Preconditions

It's very simple question, I often use com.google.common.base.Preconditions in my projects to validate arguments and parameters, for...
Jon Skeet
people
quotationmark

If you want to throw your own exception, just create your own class with similar methods to the ones in Preconditions. Each of those methods is extremely simple - adding some sort of "plug-in" ability to allow the exception class to be... more 12/20/2013 3:39:19 PM

people

Environment Variable Not recognised

I am setting Environment Variable, Still OS cant recognise. Check this out you will get it. https://www.dropbox.com/s/raqr4wbtoxxz0b8/1.JPG I tried with Admin privileges also...
Jon Skeet
people
quotationmark

You don't have javac in your path. Setting the JAVA_HOME and/or JRE_HOME environment variables (which aren't needed any more, for the most part) does nothing to the PATH which the command shell uses to find executables. Put the relevant... more 12/20/2013 3:01:24 PM

people

Use variable outside switch statement + asp.net mvc

In my Index Action in my Controller I have this: public ActionResult Index(string sortOrder) { var model; ViewBag.CitySortParm = String.IsNullOrEmpty(sortOrder) ?...
Jon Skeet
people
quotationmark

Why doesn't this work Two reasons: You're trying to use var without specifying an initial value. You can't do that - the compiler can't infer the type. You're trying to read from the model variable when it may not be initialized -... more 12/20/2013 1:40:41 PM

people

How do I check a list of c++/cli ref items for contains?

A c++/cli ref class DataEntity implements Equals and HashCode. I can check the behavior of the Equals implementation via: entity1.Equals(entity2); (C# source) and it works...
Jon Skeet
people
quotationmark

My guess is that you've implemented an overload like this: public bool Equals(DataEntity entity) That will not be called by Contains. However, if you override the Equals(object) method declared in System.Object, that will be... more 12/20/2013 1:09:34 PM

people