Browsing 7239 questions and answers with Jon Skeet

prevent users from showing XML file on server .NET

I'm building a trivia game that retrieve questions from XML file using javascript. But the XML file is available to those who got the full path to the XML file. How can i prevent...
Jon Skeet
people
quotationmark

If it's going to be available to the client via Javascript, it's got to be available to the client in general. Now you could encrypt it, then decrypt it in the Javascript - but that's more of an obfuscation technique than anything else...... more 1/10/2014 12:41:26 PM

people

C# NetworkStream.Read reads more than specified

40-50 on the package, the program reads 2 - 4 bytes greater than the specified (temp), what could be wrong? size = nsgsout.Read(buf, 0, 2); while (size != 2) { size +=...
Jon Skeet
people
quotationmark

I don't think this does what you think it does: temp - size+2 I suspect you expect it to mean: temp - (size + 2) But it's really equivalent to (temp - size) + 2 I suspect you really want the call to be: size += nsgsout.Read(buf,... more 1/8/2014 2:42:32 PM

people

Get local Date as long in android, confusion maybe?

I might have little confusion about Date in android/java. What I know is when calling new Date() it creates a Date instance with current UTC date and time, Right ? Because Date in...
Jon Skeet
people
quotationmark

So if I call new Date().getTime() I will get a long value(time stamp) as UTC, not as local time, right? Well, it will give you the number of milliseconds since Jan 1st 1970 00:00:00 UTC, yes. It's not "in" UTC particularly; it's just... more 1/8/2014 4:02:03 AM

people

Can I use a logical OR operator to test two conditions in if statement?

I have a start button and a popup menu option that do the same thing. Is it possible to test both buttons in the same if statement or do I have to write two separate if statements...
Jon Skeet
people
quotationmark

The only problem here is the brackets. An if statement is of the form: if (condition) body Currently you've got if (condition1) || (condition2) body which isn't valid. You just want: if (e.getSource() == start || e.getSource()... more 1/8/2014 2:11:11 AM

people

Casting result of Dictionary of objects after Skip and Take

I have a Dictionary of objects defined like this - Dictionary<string, MyObject> myObjectDictionary I would like to grab items in the Dictionary based of an index and...
Jon Skeet
people
quotationmark

Well, you can create a new dictionary: Dictionary<string, MyObject> myNewObjectDictionary = myObjectDictionary.Skip(startNumber) .Take(count) .ToDictionary(pair => pair.Key, pair... more 1/7/2014 9:03:31 PM

people

In C#, How can I copy a file with arbitrary encoding, reading line by line, without adding or deleting a newline

I need to be able to take a text file with unknown encoding (e.g., UTF-8, UTF-16, ...) and copy it line by line, making specific changes as I go. In this example, I am changing...
Jon Skeet
people
quotationmark

Remember, I have no a priori knowledge of the input file encoding. That's the fundamental problem to solve. If the file could be using any encoding, then there is no concept of reading "line by line" as you can't possibly tell what... more 1/7/2014 8:20:53 PM

people

Jon Skeet's Edulinq Empty Array Caching

I was going through Edulinq by Jon Skeet, and I came across the following code, Page 23, in which he implements cache mechanism for Empty() operator of Linq private static class...
Jon Skeet
people
quotationmark

My question is, how does this actually cache the Array variable? The CLR caches it per type argument. Basically, EmptyHolder<int> is a different type to EmptyHolder<string> etc, and the type initializer is invoked... more 1/7/2014 5:51:33 PM

people

Data Set Debug Error

Error of IndexOutOfRange -- Can not find table 0 -- here is my code it hits the foreach line and throws the error. What should I update so this executes? SqlCommand comnd = new...
Jon Skeet
people
quotationmark

You're never populating the DataSet - you're creating a SQL command, but never executing it. You're not querying the database at all. It's not clear whether you really need a DataSet, to be honest - you could potentially just use a reader... more 1/7/2014 4:41:04 PM

people

Regarding Static Variable

int a; static int a; Both takes same memory I just came by this today and i don't know the use of doing so :: private static final float INDICATOR_RADIUS = 1.0f; this is...
Jon Skeet
people
quotationmark

int a; static int a; Both takes same memory No, they don't. The first takes up four bytes per instance of your class. The second takes up four bytes, whether there are 0 instances or 100 instances. The field is related to the type,... more 1/7/2014 2:27:17 PM

people

Getting the same data into a buffer from TCP/IP server

At the client I use additional thread which executes this method: public void FillBuf(object sender) { var handler = (Socket)sender; while (true) { received = 0; while...
Jon Skeet
people
quotationmark

In your client code, you're reusing the same byte array over and over, then enqueuing a reference to it. You need to create a new byte array for each buffer: public void FillBuf(object sender) { var handler = (Socket)sender; ... more 1/7/2014 12:43:00 PM

people