Browsing 7239 questions and answers with Jon Skeet

Not all code paths return a value for Array

I'm getting the following error: Not all code paths return a value for Array Here is my code: public Product[] LoadAllDatas() { SqlConnection con = new...
Jon Skeet
people
quotationmark

Well, you basically need to think about what happens if dr.Read() returns false - i.e. if there are no results. You may well want to throw an exception in that case... or possibly return an empty array. Additionally, you should use using... more 7/22/2014 5:54:51 AM

people

US and UK format in datetime output

C#: I want to get date time object dependent to culture specific. Input can be in dd/mm/yyyy or mm/dd/yyyy. Output should be culture specific. If input : en-US and format of...
Jon Skeet
people
quotationmark

I want to get date time object dependent to culture specific. There's no such concept. Even the calendar system isn't part of DateTime. The same DateTime value is used to represent a single value regardless of culture. However, you... more 7/21/2014 7:09:00 PM

people

How to write multiple messages in one protobuf file?

Take the google's tutorial for examples: message Person { required string name = 1; required int32 id = 2; optional string email = 3; enum PhoneType { MOBILE = 0; ...
Jon Skeet
people
quotationmark

I haven't tried this, but I'd expect it to work: Writing: CodedOutputStream output = CodedOutputStream.newInstance(...); while (...) { Person person = ...; output.writeMessageNoTag(person); } Reading: CodedInputStream input =... more 7/21/2014 7:05:09 PM

people

Group and Join Linq statement wont pass to my view from controller

My View: @model IEnumerable<TestingMainPage.Models.SummaryModel> @if (Model.Count() > 1 ) {//Do something} else {//Do something else} The error involved: The model...
Jon Skeet
people
quotationmark

This is the problem, at the end of your query: select new { Recid = g.Key.recid, datetimestamp = g.Key.datetimestamp, status = g.Key.status, Qty = g.Sum(p => p.b.qty) } That's an anonymous type, but your view wants an... more 7/21/2014 6:54:57 PM

people

Writing the byte array to sub folder in java

Currently I am making one folder with help of File class String homeDir = System.getProperty("user.home"); // this will return C:\Users\username byte[] b1 = abc.getValue(); //...
Jon Skeet
people
quotationmark

You have two problems: 1) You're assuming that calling the File constructor will create a directory if it doesn't exist. That's not the case. 2) You're calling the FileOutputStream constructor and passing in the home directory, not the... more 7/21/2014 6:03:52 PM

people

XML Child Node count Java

I need to get the count of the number of child nodes underneath a parent tag <test> in the below example. So count of <username>, <password> and <result>...
Jon Skeet
people
quotationmark

To get the number of child elements within a particular element, you need to take account of the fact that not all nodes are elements. For example, you could use: static int getChildElementCount(Element element) { int count = 0; ... more 7/21/2014 4:17:42 PM

people

await in try finally block

I've been playing around with the Visual Studio 14 CTP 2. This version of C# vNext enables the use of the await keyword inside a finally block. I am trying to figure out how this...
Jon Skeet
people
quotationmark

The compiler is just turning: try { Foo(); } finally { Bar(); } into something like: Exception caught = null; try { Foo(); } catch (Exception e) { caught = e; } Bar(); if (caught != null) { throw caught; } ... but... more 7/21/2014 2:36:02 PM

people

Using the await operator with Lua

I'm using NLua and I'm having trouble with one of my methods that I'm registering. It's a method that returns a Task of bool and it's async, meaning I have to include the await...
Jon Skeet
people
quotationmark

It's a method that returns a Task of bool and it's async, meaning I have to include the await operator before it. You don't have to use await with methods returning tasks - that's just a feature of C# which makes it easier to write... more 7/21/2014 1:56:55 PM

people

computing checksum for an input stream

I need to compute checksum for an inputstream(or a file) to check if the file contents are changed. I have this below code that generates a different value for each execution...
Jon Skeet
people
quotationmark

You're using the same stream object for both calls - after you've called checkSum once, the stream will not have any more data to read, so the second call will be creating a hash of an empty stream. The simplest approach would be to create... more 7/21/2014 1:46:18 PM

people

Windows 8 phone System.StackOverflowException while filling a listbox using class system

I have the error System.StackOverflowException, everytime I run my app. This error is located in the last line of my History class. Below: public class userHistory { public...
Jon Skeet
people
quotationmark

Look at this part of userHistory: public List<userHistory> lstUserHistory { get; set; } public userHistory(string timedate, string url) { lstUserHistory.Add(new userHistory(timedate, url)); } There are two bugs here: The... more 7/21/2014 10:12:22 AM

people