Browsing 7239 questions and answers with Jon Skeet

Convert string to double or float c#

I need to convert a string to double. Or float, whatever suits best for this type of conversion. The string is "25.00". How would I convert this string so that I can use it in...
Jon Skeet
people
quotationmark

I suspect your default culture info uses comma as a decimal separator instead of dot. If you know your input will have a dot, it's best to specify the invariant culture explicitly: double d1 = double.Parse(s1,... more 8/16/2014 8:17:49 AM

people

Error instantiate a Generic class

I'm create C# windows application and using FluentValidation for validating a View Model. In every form I always create validation method like this: private bool...
Jon Skeet
people
quotationmark

You're trying to assign a CustomerValidator reference to a variable of type T. What if T is StringBuilder or something like that? Fundamentally, it seems odd for your ValidationHelper to claim to be generic, but then be specific to... more 8/16/2014 7:20:58 AM

people

XML compare Elements and Values using LINQ to XML

XElement client = new XElement("Root", new XElement("Child2", "2"), new XElement("Child1", "1"), new XElement("Child3", "hello world"), new...
Jon Skeet
people
quotationmark

Finding the element name differences is easy: var clientElementNames = client.Elements().Select(x => x.Name); var serverElementNames = server.Elements().Select(x => x.Name); var clientOnly =... more 8/15/2014 8:22:12 PM

people

Add object to list of same object

I got this to classes: public class NotifyUser : ContentPage { public NotifyUser() { Friends = new List<FriendStatus>(); } public string Namn { get;...
Jon Skeet
people
quotationmark

I strongly suspect that this line is the problem: var loggedinuser = RavenSession.Load<ContentPage>("NotifyUser/" + user) as NotifyUser; loggedinuser will be null if the Load method actually returns something other than a... more 8/15/2014 4:34:44 PM

people

Intrinsic/Monitor Locks and Inheritance

Background: I'm reading Java Concurrency in Practice, and Listing 2.7 has the following code. The example states that this code only functions because monitor locks are...
Jon Skeet
people
quotationmark

I would have originally thought that when you called super.doSomething() then it would have acquired a lock on the base class object and not the derived class object. There's only one object - if you create an instance of... more 8/15/2014 1:16:31 PM

people

How null values was entered to datetime prior to Nullable types?

Nullable types was introduced in .NET 3.X. Assume i have DB table with column of type datetime that accepts null values. If the column data suppose to come from a windows forms...
Jon Skeet
people
quotationmark

Nullable types was introduced in .NET 3.X No, they were introduced in .NET 2.0. See the documentation. How do i created a property of type datetime and make it accept null so i can send null values to my DB table column? You... more 8/15/2014 1:04:15 PM

people

Why a ClassCastException but not a compilation error?

Why don't I get a compilation error in the code below? I get a ClassCastException which is a little confusing. Is it because they are related? class Ink {} Interface Printable...
Jon Skeet
people
quotationmark

Why don't I get a compilation error in the code below? Because the compiler only cares about the static type of the expression you're trying to cast. Look at these two lines: BlackInk blackInk = new BlackInk(); printable =... more 8/15/2014 12:44:56 PM

people

Why does indexOf method of ArrayList work?

Please consider the following code (Its quite simple) public class Main { public static class A{ int id; public A(final int id){ this.id = id; ...
Jon Skeet
people
quotationmark

You're confusing the compile-time type of a variable with the execution-time type of its value. The A.equals method will be called rather than Object.equals because of overriding - the execution-time type is used to determine which... more 8/15/2014 8:46:40 AM

people

How to find highest value from an array, if there are more than one high value?

I have an array which I would like to find the highest value for, but this value might be repeated. For example, consider this array of integers: {10, 2, 6, 25, 40, 58, 60,...
Jon Skeet
people
quotationmark

There are various approaches you could take here: Sort the array using Arrays.sort, then work from the end until you saw a different value... letting you work out the value and the count, which you could then multiply together. This is... more 8/15/2014 6:14:39 AM

people

DateTime Format not being recognized

I have a date that I need to get into a DateTime object. In my code below I set the filedate to the date string that I get and then try two different formats (patern and patern2....
Jon Skeet
people
quotationmark

Three problems: Your two pattern straings are identical - why try them both? hh means hour of 12-hour clock; 16 isn't a valid value You should escape the CDT part as you want it as a literal I suspect you want: "ddd MMM d HH:mm:ss... more 8/14/2014 8:58:53 PM

people