Browsing 7239 questions and answers with Jon Skeet

How to set encoding result to TextBox

How do I set the result of my encoding to a TextBox? string myString; myString = "Hello World"; byte[] data = Encoding.ASCII.GetBytes(myString); textBox1.Text =...
Jon Skeet
people
quotationmark

You can't set the encoding of a text box, but it sounds like you're just trying to display some binary data in a text box... did you want hex, for example? If so, BitConverter.ToString(byte\[\]) is your friend: textBox1.Text =... more 9/16/2014 3:58:36 PM

people

java.text.ParseException: Unparseable date: convert mm/dd/yyyy string to a date

when i convert my string object in mm/dd/yyyy format to Date it gives me java.text.ParseException: Unparseable date: "09/17/2014" i am trying to do it like this : String...
Jon Skeet
people
quotationmark

There are several potential problems here: You're not specifying a format You're not specifying a locale You're not specifying a time zone You're trying to cast the return value (which will be a java.util.Date reference) to a... more 9/16/2014 3:28:25 PM

people

Forcing two parameters of a generic method to have the same concrete type

How can I have a method with two parameters, with both parameters having the same concrete type? For example, boolean equals(Object a, Object b) allows for a of any type and b...
Jon Skeet
people
quotationmark

You can't, basically. There's no way of doing that. Even if you could do it for a simple call to prohibit arguments of different types, it could always be bypassed using a cast: equals((Object) date, (Object) string) If you're... more 9/16/2014 11:11:49 AM

people

how to get country name from latitude and longitude

How can i get the country name from latitude and longtitude using c#? Im using the Bing.Map API Location location12 = new Location(location.Latitude,...
Jon Skeet
people
quotationmark

You'll want to use a reverse geocoding API of some kind. For example: The Bing Maps API (the webservice) The Google Geocoding API The Geonames API If you're already using the Bing.Maps SDK, you should use the Map.SearchManager property... more 9/16/2014 10:16:34 AM

people

Absolute difference of a TimeSpan object with a timing interval in scale of month and year

I am in some trouble within a simple timing manipulation in C#. The user defines two DateTime objects, as the start and the end of a time interval: DateTime From = new...
Jon Skeet
people
quotationmark

This is the sort of thing that my Noda Time project is designed to handle. It has a Period type which does know about months and years, not just a fixed number of ticks. For example: LocalDateTime start = new LocalDateTime(2014, 1, 1, 8,... more 9/16/2014 7:13:53 AM

people

If parent method throws checked exception, then is it compulsory to throw the same exception in child class?

Given: static class A { void process() throws Exception { throw new Exception(); } } static class B extends A { void process() { System.out.println("B "); } } public...
Jon Skeet
people
quotationmark

The point is that the compiler doesn't know that you're calling an overridden method which doesn't throw any checked exceptions. When it sees: a.process(); it doesn't "know" that the value of a is actually a reference to an instance of... more 9/16/2014 6:28:43 AM

people

How to get xml attribute values using Document builder factory

How to get attribute values by using the following code i am getting ; as output for msg . I want to print MSID,type,CHID,SPOS,type,PPOS values can any one solve this issue...
Jon Skeet
people
quotationmark

You need to use @ in your XPath for an attribute, and also your path specifier for the second element is wrong: String msg = xpath.evaluate("/message/che/@CHID", document); String status = xpath.evaluate("/message/che/pds/position/@PPOS",... more 9/16/2014 5:45:38 AM

people

Xelement converting special characters to strings

The below XElement converts the special character "&" to "&". XElement newElement = new XElement("testting", "wow&testvalue"); I want it to be the "&" not...
Jon Skeet
people
quotationmark

I want it to be the "&" not &. Then it would be invalid XML. Why do you want invalid XML? LINQ to XML is expressing the text you've requested in valid XML. That's what it's meant to do. If you ask for the text of the element... more 9/16/2014 5:27:10 AM

people

Cannot convert type 'T' to bool

Basically I'm having these errors where the code is in bold: Cannot convert type 'T' to bool Cannot convert type 'T' to string x2 Cannot convert type 'T' to byte[] Cannot convert...
Jon Skeet
people
quotationmark

Unfortunately the rules for generic conversions in C# don't allow for this directly, but you can go via object. For example: byte[] data = (byte[]) (object) value; However, you might consider whether it's really appropriate for this to... more 9/14/2014 4:39:57 PM

people

What is the propper way to get a char's code point?

I need to do some stuff with codepoints and a newline. I have a function that takes a char's codepoint, and if it is \r it needs to behave differently. I've got this: if...
Jon Skeet
people
quotationmark

If you know that all your input is going to be in the Basic Multilingual Plane (U+0000 to U+FFFF) then you can just use: char character = 'x'; int codePoint = character; That uses the implicit conversion from char to int, as specified... more 9/13/2014 7:37:55 PM

people