Browsing 7239 questions and answers with Jon Skeet

Conflict between NULL value in a DB and DateTime attributes

I have a class with a field named myDateTime typed as nullable DateTime, these are the accessor methods: System.DateTime? _MyDateTime; public System.DateTime? MyDateTime {get;...
Jon Skeet
people
quotationmark

You need to convert from DBNull.Value to the null value of DateTime?. It may be simplest to write an extension method on DbDataReader for that: public static DateTime? GetNullableDateTime(this DbDataReader reader, ... more 10/26/2013 1:52:50 PM

people

Why is my program freezing when I use a method? (Java)

When I use a boolean method in the Main body, my program freezes and stops working. I've tried putting the method at different places but the exact same thing happens - it...
Jon Skeet
people
quotationmark

I suspect it hasn't frozen - it's just waiting for input. Unfortunately it hasn't told you that it's waiting for input due to the ordering of these two statements: int input = keyboard.nextInt(); out.println("If you want to add an item,... more 10/26/2013 9:45:47 AM

people

Java List sorting doesn't work

I'm trying to sort a hashmap's by sorting it's keys but it doesn't work. The sorting criteria is given by the length of a list that is the hashmap's value. See code below with...
Jon Skeet
people
quotationmark

Plain hashmaps are inherently unordered. You can't sort them, or assume anything about the order in which the entries are retrieved when iterating over them. Options: Use a TreeMap if you want to sort by key. Use a LinkedHashMap if you... more 10/26/2013 9:24:06 AM

people

virtual List<T> :“The function evaluation requires all threads to run”

I am following the following tutorial to learn code fast. Code First to a New Database I have done till the step 4: of the tutorial, the problem arises when i try to run my code....
Jon Skeet
people
quotationmark

The exception message shows that you've used Blog and Post as classes nested within Program, whereas the instructions state: Below the Program class definition in Program.cs add the following two classes. Personally I'd put them into... more 10/26/2013 8:40:57 AM

people

OrderBy on Enum.GetValues()

I'm populating a DropDownList in MVC 4 from an enum and I want to order the enum values from largest to smallest. However, there doesn't seem to be a direct way of approaching...
Jon Skeet
people
quotationmark

Sounds like you just want: var priorities = ((Models.Priority[]) Enum.GetValues(typeof(Models.Priority))) .OrderByDescending(x => x); Or to avoid quite as many brackets: var priorities =... more 10/25/2013 8:54:26 PM

people

Explanation for this diamond notation?

From a official Java JDK1.7 guide, I got this quote, but I don't understand how it works. Can anyone explain? In other words, how does the diamond infer a Integer type when its...
Jon Skeet
people
quotationmark

The Integer part is inferred from the usage of the result of the constructor call - it's assigning to a variable of type MyClass<Integer>, hence the Integer part is inferred for the diamond. The constructor argument is irrelevant to... more 10/25/2013 3:48:58 PM

people

How to use persian variable in sqlite in android?

I create table in android sqlite. My table is category: db.execSQL("CREATE TABLE IF NOT EXISTS category (id_category INTEGER PRIMARY KEY AUTOINCREMENT,sub INT(5),name...
Jon Skeet
people
quotationmark

You shouldn't include the value directly in your SQL at all. Instead, use parameterized SQL, such as: Cursor cursor = db.rawQuery("SELECT * FROM category WHERE name=?", new String[] { a }); That way: You... more 10/25/2013 3:45:10 PM

people

Grouping collections of the same type C#

I have a collection of differents objects and I want to know if I can create collections grouping the same type of objects. I don't know if there is a method with linq or...
Jon Skeet
people
quotationmark

LINQ can do this very easily returning a single lookup collection: var lookup = list.ToLookup(x => x.GetType()); You can then: Iterate over it to find all the types and the associated objects Fetch all the items of a specific type... more 10/25/2013 1:25:35 PM

people

How to writte protobuf serialized content directly to SharpZipLib stream

Is there possible to writte protobuf serialized content directly to SharpZipLib stream? When I try to do this, looks like the provided stream is not filled with the data from...
Jon Skeet
people
quotationmark

This is the problem, I believe (in the original code in the question): public void Serialize(Stream outputStream, T3 content) { using (var stream = new MemoryStream()) { Serializer.Serialize(stream, content); ... more 10/25/2013 1:21:41 PM

people

Timezone codes conversion between SQL server and Java

I have a table in SQL server which stores the TimeZone codes as the format listed here: TimeZone Microsoft. I wonder if there is a way to get this TimeZone code correctly in Java...
Jon Skeet
people
quotationmark

There's mapping information between Windows time zone IDs and IANA IDs in CLDR - it's reasonably easy to read the XML, and you may well find there's a Java library around to parse this for you. However, it's worth being aware that the... more 10/25/2013 12:38:41 PM

people