Browsing 7239 questions and answers with Jon Skeet

Images not referenced by solution explorer in Visual Studio 2013

I am using webcam to create images, i am saving that images in to the folder which belongs to another project. after saving the images its not reflecting in that folder, when i...
Jon Skeet
people
quotationmark

Projects (pre-ASP.NET 5, anyway) specify exactly which files are within them - Solution Explorer isn't a file-system explorer. If you right-click on the folder and choose "Add... Existing Item" then you should be able to add the new... more 2/26/2015 6:51:05 AM

people

Access to JSON Data Properties

I have the following string { data: [ {"Href":"1.jpg","Id":1,"Height":55,"Width":55,"Index":0}, ...
Jon Skeet
people
quotationmark

I would suggest using "LINQ to JSON" instead of DeserializeObject, personally - although that may just due to having more experience with it: using System; using System.IO; using Newtonsoft.Json.Linq; class Program { static void... more 2/25/2015 10:16:36 PM

people

Write a validation routine for a C# class on change event

I'm trying to write an "onchange" event for a C# class that I have. The idea would be to capture anytime the class was instantiated or a property was changed and fire off some...
Jon Skeet
people
quotationmark

You don't really need a field for this at all - unless the validation is costly (so you want to avoid recomputing it each time it's requested) you can just have: public string Source { get; set; } public string Destination { get; set;... more 2/25/2015 7:19:12 PM

people

How to get an enum value ASP.NET MVC

I have a ProjectsModel as a viewmodel: public IEnumerable<TheProjects> OurProjects { get; set; } public class TheProjects { public int Id { get; set; } public...
Jon Skeet
people
quotationmark

Just cast: TheProjects x = ...; PriorityForProject priority = (PriorityForProject) x.Priority; (I'd strongly advise you to rename the TheProjects type though - that's a really unwieldy, unidiomatic name...) more 2/25/2015 5:17:13 PM

people

NLog breaks when using operator '<'

I have a configuration below and a relational operator '<' seems to be not escaped because it outputs error XML element is not closed. In documentation they have an example...
Jon Skeet
people
quotationmark

Am I missing something? Yup, you're not taking into account that this is XML, where < needs to be escaped. You want: <logger name="*" minlevel="Trace" writeTo="logFile"> <filters> <when... more 2/25/2015 3:13:42 PM

people

Exception Handling: Local Variables

In the following code integers n1 and n2 can be accessible inside the try block. However they are not recognized by catch and finally block. May I know the reason?! There is...
Jon Skeet
people
quotationmark

However they are not recognized by catch and finally block. May I know the reason?! Sure - they're not definitely assigned. Imagine Console.ReadLine throws an exception. You catch that exception - but you haven't assigned a value to... more 2/25/2015 2:44:47 PM

people

DateTimeOffset default value

I would like to set default value to DateTimeOffset - it should not be DateTime.Now but rather DateTime.MinValue or default(DateTime) Any thoughts how can I do it? This...
Jon Skeet
people
quotationmark

The reason this code throws an exception for you is that you're presumably in a time zone which is ahead of UTC - so when DateTime.MinValue (which has a Kind of Unspecified) is converted to UTC, it's becoming invalid. The conversion is... more 2/25/2015 1:18:53 PM

people

EnumMap raise NullPointerException

I've got a Enum and an EnumMap<Parameters, Byte>. I put the map into a class to hide the "byte" values. So I have a set(Parameter, int) and set(Parameter, boolean)...
Jon Skeet
people
quotationmark

The problem is the way you're using the return value of put, which is documented as: the previous value associated with specified key, or null if there was no mapping for key. (A null return can also indicate that the map previously... more 2/25/2015 1:05:19 PM

people

Append Strings Performance issue Java 6

I need to repeatedly append strings (for about 50 times), which is a substring of another StringBuilder. I need to do this for around 30k inputs. It takes me a time of around 6...
Jon Skeet
people
quotationmark

You can definitely avoid creating so many objects using the overload of append which allows you to specify a subsequence: for (...) { output.append(input, 1, 8); output.append(input, 33, 45); output.append(input, 20,... more 2/25/2015 11:52:32 AM

people

Linq to xml parsing

I need assistance in retrieving the element Country and Its value 1 in the below code. Thanks in advance. <?xml version="1.0" encoding="utf-8"?> <env:Contentname...
Jon Skeet
people
quotationmark

This is the problem, for two reasons: var str = item.Element("Document").Element("country"); Firstly, XML is case-sensitive - you want Country, not country. Secondly, those elements inherit the namespace declared with xmlns=... in the... more 2/25/2015 11:31:46 AM

people