Browsing 7239 questions and answers with Jon Skeet

Passing Classes with same interface or base class to overloaded methods

I have a base class with has x amount of properties, I then have derived classes with more properties. How do I process the common fields in a method and then send the object to...
Jon Skeet
people
quotationmark

It sounds like you basically want overload resolution at execution time. (I'm assuming you can't introduce a virtual method to do the right thing, and implement it in each class. That would be the cleanest way if it's reasonable for the... more 6/17/2015 4:27:51 PM

people

Does string interpolation evaluate duplicated usage?

If I have a format string that utilizes the same place holder multiple times, like: emailBody = $"Good morning {person.GetFullName()}, blah blah blah, {person.GetFullName()}...
Jon Skeet
people
quotationmark

Yes, it will be evaluated twice. It can't know that it is the same value. For example: Random rng = new Random(); Console.WriteLine($"{rng.Next(5)}, {rng.Next(5)}, {rng.Next(5)}"); It's exactly the same as if you just used the... more 6/17/2015 4:14:19 PM

people

can we call a method having argument as java.lang.reflect.Array?

I am having doubt on below code which uses parameter as java.lang.reflect.Array. public static void display(java.lang.reflect.Array stringArray) { ...
Jon Skeet
people
quotationmark

Array is just a helper class - note how all the methods on it are static. I wouldn't expect there to ever be an instance of it. To accept an array - and any array, including int[] etc - you'd need to make the method accept Object: public... more 6/17/2015 1:28:50 PM

people

Deleting a link in a LinkedList

Hi I have the following code where I am trying to delete a link from a LinkedList. I am able to delete the node, but whenever I try to iterate through the list, it gives me the...
Jon Skeet
people
quotationmark

This line: first = first.nextLink is modifying a field, even though you're meant to just be looping to find the right link. That seems like a very odd thing to do. I'd expect to have something like: public void deleteLinkNumber(int... more 6/17/2015 6:25:17 AM

people

Deny direct url access to files in Jetty 7

I have a single page website using jetty 7 that shows another pages using ajax call. Does anyone have any suggestions on how to only show the pages using ajax call in my site and...
Jon Skeet
people
quotationmark

A few options: Your ajax call could return an encrypted form of the data, and the client side could decrypt it. Your ajax call could include some sort of token which was originally provided on the single accessible page, and you could... more 6/17/2015 6:09:08 AM

people

save hash value in the database

i used this functions to compute the hash value: public string GetSHA512(string input) { byte[] data, result; StringBuilder hash = new StringBuilder(); data =...
Jon Skeet
people
quotationmark

Currently you're just returning the decimal representation of all the bytes, concatenated together. So { 0, 0, 0 } ends up as "000" whereas { 123, 123, 123 } ends up as "123123123". So yes, both those hashes will give the same output size... more 6/17/2015 5:58:05 AM

people

Delete this token (else)

ok so i was playing round with some code and adding new line as i'm learning java. i got this error "syntax error token "else" delete this token". As im new to this could some...
Jon Skeet
people
quotationmark

You have an unconditional else block - you can't follow that with another else. So this is fine: if (condition) { ... } else if (otherCondition) { ... } else { ... } But this isn't - because it doesn't make sense: if... more 6/16/2015 6:12:01 PM

people

static void c# webmethod can't reference user control?

I have a WebMethod where I just want to flip a property to true. I am putting it in the code-behind of a .aspx page using C#. public partial class Data : Base { protected...
Jon Skeet
people
quotationmark

I am getting the error that this is not valid in a static property. Indeed. In fact, in this case, it's a static method. A static member is one which is associated with the type, rather than with any instance of the type - so here,... more 6/16/2015 6:09:53 PM

people

c# to vb using Sync Framework strange error

I followed Microsoft's walkthrough for Sync Framework which is written in C#. And I wish to translate it to VB. I have simplified the code as much as possible. Both codes compile...
Jon Skeet
people
quotationmark

The C# code contains doubled backslashes in the connection strings, because that's needed to escape them in string literals (or using a verbatim string literal). In VB that's not needed as \ isn't an escape character (as far as I'm aware)... more 6/16/2015 4:19:50 PM

people

How to get Rid of Duplicate Keys in Dictionary C#

I keep on getting the error: Item has already been added. Key in dictionary: '@QueryID' Key being added: '@QueryID'. I did some research on this and it tells me that I'm...
Jon Skeet
people
quotationmark

You've created a single Hashtable outside your loop, then one on every iteration inside your loop. However, you're unconditionally adding to the single "outer" hashtable within the loop, so on the second iteration it's bound to... more 6/16/2015 4:08:33 PM

people