Browsing 7239 questions and answers with Jon Skeet

convert RGB int value to Hex format with 0x prefix in c#

I am trying to convert an RGB value to hex format in c# using this code : int ColorValue = Color.FromName("mycolor").ToArgb(); string ColorHex = string.Format("{0:x6}",...
Jon Skeet
people
quotationmark

Just add the 0x part yourself in the format string: // Local variable names to match normal conventions. // Although Color doesn't have ToRgb, we can just mask off the top 8 bits, // leaving RGB in the bottom 24 bits. int colorValue =... more 10/2/2014 12:12:32 PM

people

How can I cast an Object in an equals override method in Java?

I have the following code in a class used to simulate the IRS with employer filings in accordance with the filer. I am required to override the equals class but I keep getting the...
Jon Skeet
people
quotationmark

For expressions like this: (Employer)obj.getEmployeeSSN() The . has higher precedence - "binds tighter" - than the cast. So it's closer to: (Employer) (obj.getEmployeeSSN()) ... whereas you want: ((Employer)... more 10/1/2014 8:54:22 PM

people

Single/double dispatch via "dynamic overload" in C#

Why double dispatch via "dynamic overload" based on argument type isn't natively supported by C#? I see this would require dynamic dispatching but since virtual method calls are...
Jon Skeet
people
quotationmark

Why double dispatch via "dynamic overload" based on argument type isn't natively supported by C#? It is, via dynamic typing: static void Main(string[] args) { var objs = new object[] { new Class1(), new Class2() }; // Note... more 10/1/2014 8:17:28 PM

people

What is the difference between namespace dot namespace and nested namespace?

Is there any difference between: namespace Outer.Inner { } And namespace Outer { namespace Inner { } } in C#?
Jon Skeet
people
quotationmark

Assuming you don't put any other declarations or using directives in the Outer namespace, there's no difference at all. Given that you would very very rarely declare members in multiple namespaces within a single file, I'd suggest using... more 10/1/2014 8:09:49 PM

people

If I have a class called 'exceptions' and it has only static classes, is this breaking Java standards?

If I have class like this, which is essentially just a package object, is it breaking standards to have it follow the package naming conventions? I thought I remembered reading...
Jon Skeet
people
quotationmark

If I have class like this, which is essentially just a package object, is it breaking standards to have it follow the package naming conventions? Yes. It's not a package, it's a class, so it should follow class naming conventions...... more 10/1/2014 6:25:25 PM

people

Issue creating XML doc from Dictionary

My intention is to iterate through my lovely dictionary (both key and value are strings) and create an xml file from it. I get the error on the last line (saving the xml). ...
Jon Skeet
people
quotationmark

Currently you're adding multiple elements directly to the document - so you'd end up with either no root elements (if the dictionary is empty) or potentially multiple root elements (if there's more than one entry in the dictionary). You... more 10/1/2014 4:11:10 PM

people

Why is that Thread interupt method is not breaking its sleep method?

I have this program below package com; public class ThreadDemo implements Runnable { @Override public void run() { while(true) { try { ...
Jon Skeet
people
quotationmark

You're in a loop: You're sleeping Being interrupted and printing the stack trace Going back to sleep Never being interrupted again So it is "coming out of sleep state" (otherwise you wouldn't see the stack trace) - but you're then... more 10/1/2014 3:14:49 PM

people

Having trouble with Character.isWhiteSpace() in Java

I have this one problem for homework that I need to solve. The code is working fine, except for the white space option. NetBeans gives me a warning when I use .isWhiteSpace, but...
Jon Skeet
people
quotationmark

The problem is your use of Scanner.next(): Finds and returns the next complete token from this scanner. A complete token is preceded and followed by input that matches the delimiter pattern. The default delimiter for Scanner is... more 10/1/2014 3:04:23 PM

people

What is the C# equivalent to VB.NET's CType Function for use with generic types?

Assume I have a table called MyTable in a SQL Server database called MyDB with the following three records: |ID|MyVarcharColumn| -------------------- |1|123| |2|2014-10-01 9:58...
Jon Skeet
people
quotationmark

If you only need to support a very specific set of types that are supported by it, then Convert.ChangeType may be okay: object value = (string) ds.Tables[0].Rows[0]["MyVarcharColumn"]; return (T) Convert.ChangeType(value,... more 10/1/2014 2:42:17 PM

people

Is SQL server 2008 storing uf8

I have a java servlet that is using utf8. I have entered numerous characters (chinese traditional, russian, etc) and they seem to be stored in and retreived from sql server 2008...
Jon Skeet
people
quotationmark

No, your string is actually UTF-16-encoded - it's a Java string, and Java strings are sequences of UTF-16 code units. It (mostly) doesn't matter how SQL server stores the value internally, so long as it can represent the same character... more 10/1/2014 2:09:36 PM

people