Browsing 7239 questions and answers with Jon Skeet

Creating daylight savings aware DateTime when server set to UTC

My application is hosted on Windows Azure, which has all servers set to UTC. I need to know when any given DateTime is subject to daylight savings time. For simplicity, we can...
Jon Skeet
people
quotationmark

Your last line specifies that the value is in the local time zone of the system it's running in - but it's not really... it's converted using a different time zone. Basically DateTime is somewhat broken, in my view - which makes it hard... more 1/6/2014 8:21:42 AM

people

Array error with string

I have an issue with string array where's the program takes the use names the put it in the screen. I did some coding and creating 2D games and android app but the fact I never...
Jon Skeet
people
quotationmark

I'm guessing you're getting an ArrayIndexOutOfBoundsException due to your loop bounds: for(i =0; i <= Chatlength.length ; i++){ That should be: for (int i = 0; i < Chatlength.length; i++) { ... using a local variable... more 1/6/2014 7:54:00 AM

people

Why does HashSet allow equal items if hashcodes are different?

The HashSet class has an add(Object o) method, which is not inherited from another class. The Javadoc for that method says the following: Adds the specified element to this...
Jon Skeet
people
quotationmark

You've violated the contract of equals/hashCode basically: From the hashCode() docs: If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same... more 1/6/2014 6:55:45 AM

people

Determine the namespace of a C# file

How can I determine the namespace of a C# class if it is not defined in the file. For example, from a class like this: public partial class MyClass : System.Something { ...
Jon Skeet
people
quotationmark

If no namespace is declared in the file, the source is in the "global" namespace. There's no namespace defaulting in C# as there is in VB. All "real" code really should be in a namespace though, for sanity. (I write toy, throwaway code... more 1/6/2014 6:50:53 AM

people

Sockets, sent pdf file always arrives zero bytes size

I'm sending a pdf file from android tablet client to Java app running on Windows 7. The file always arrives as a size of zero bytes. what is the problem here? Before the pdf file...
Jon Skeet
people
quotationmark

This is the problem, I believe. int bytesRemaining = fileSizeFromClient = totalBytesRead; That's doing two assignments, so you're assigning 0 to fileSizeFromClient immediately, and exiting the loop. You meant: int bytesRemaining =... more 1/6/2014 6:37:00 AM

people

ArrayIndexOutOfBoundsException while converting linkedList to array list

Im trying to convert a linkedList into an ArrayList as shown below. private LinkedList<myData> myLinkedList= new LinkedList<myData>(); public...
Jon Skeet
people
quotationmark

toArray failing is only one symptom of you doing something fundamentally dangerous. From the documentation of LinkedList: If multiple threads access a linked list concurrently, and at least one of the threads modifies the list... more 1/6/2014 6:13:42 AM

people

ServletContextAttributeListener.attributeReplaced() method doesn't work

I have a code which must print my atomic counter every time when I change it in a servlet. But my code didn't work. I cannot figure out what's the problem. I need to print a new...
Jon Skeet
people
quotationmark

The value of the attribute isn't changing - it's the same reference throughout the context's lifetime. When you increment the counter, that isn't changing the value of the attribute... it's just changing the data within the object that the... more 1/5/2014 8:44:56 PM

people

async Telnet Server data receiving issues

I am writing a telnet server using the async Begin/End methods. The issue that I am having is determining what within my buffer is actual data and what is not. Network coding is a...
Jon Skeet
people
quotationmark

So when call BeginReceive, I need to provide a buffer of a predetermined size. In doing that, I end up with unused bytes in my buffer array. They all have the value of 0, so I am assuming that I can loop through the array and build a... more 1/5/2014 8:55:31 AM

people

Inconsistent accessibility: field type 'TagHandler' is less accessible than field 'EditTag.tag'

I want to create a form where I can edit a field of my class TagHandler. So I decided to pass as a paramter to form's constructor TagHandler tag where tag - is a tag I want to...
Jon Skeet
people
quotationmark

These are the problem: public TagHandler tag { set; get; } public EditTag(TagHandler tag) The latter is a public method in a public class. Therefore all its parameters and its return type should be public too - otherwise you're saying... more 1/4/2014 11:43:21 PM

people

making text bold via code

I have the code: label5.Font = new Font(label5.Font.Name, 12, FontStyle.Underline); ..But I can't figure how to change it to bold as well. How can I do that?
Jon Skeet
people
quotationmark

You just need to use | to combine multiple styles: label5.Font = new Font(label5.Font.Name, 12, FontStyle.Underline | FontStyle.Bold); more 1/4/2014 11:39:18 PM

people