Browsing 7239 questions and answers with Jon Skeet

AES key converting to string and byte[] C#

I have an application that generates a AES Key (using Security.Cryptography). I take that AES Key, convert it to string and put it in a cookie like this: string keyToSend =...
Jon Skeet
people
quotationmark

It sounds like CurrentKey is arbitrary binary data - not a UTF-8 encoded string. If you've got arbitrary data which you need to encode as a string (e.g. an image, or encrypted or compressed data) you're usually best off using Base64 or hex... more 1/20/2015 10:10:14 AM

people

Upcasting java RTTI

public class A { public static void main(String[] args) { B b = new B(); A a = new B(); a.f(); A aaa = (A) b; aaa.f(); } public...
Jon Skeet
people
quotationmark

a2 is an instance of Atest, i think a2.equals(new C()) should call the function public boolean equals(C c). Although the value of a2 at execution time is a reference to an instance of Atest, the compile-time type of a2 is just Object.... more 1/20/2015 9:50:29 AM

people

What is the scope of the lock?

I've seen this piece of code from one of the jetbrain's team : Looking at this code : object myLock = new object() public IEnumerable<int> Values() { lock (myLock) { ...
Jon Skeet
people
quotationmark

If you mean in terms of time - the lock will be aquired when MoveNext() is first called, and will be released either when MoveNext() has been called for the 11th time (i.e. when the loop completes) or when the iterator is disposed. For... more 1/20/2015 8:28:55 AM

people

Binding to static list of static class

I have static class with current transaction information like this: public static class BKM { public static List<Ticket> Tickets {get;set;} } What I want to bind to...
Jon Skeet
people
quotationmark

I suspect one problem is that you want the source to be BKM.Tickets, but you want the path to be Count. So try this: <TextBlock Text="{Binding Source={x:Static p:BKM.Tickets} Path=Count}" /> And as Sriram says, you should make... more 1/20/2015 8:20:22 AM

people

Why doesn't System.out.println() throw NullPointerException?

This might be a very basic question, but I still don't know the answer. String abc = null; System.out.println(abc); Why does System.out.println print "null" and does...
Jon Skeet
people
quotationmark

It's behaving as it's documented to. PrintStream.println(String) is documented as: Prints a String and then terminate the line. This method behaves as though it invokes print(String) and then println(). PrintStream.print(String) is... more 1/20/2015 8:18:48 AM

people

init method in java.util.hashMap

while I was going through the source code of java.util.HashMap I found declaration of init. Initialization hook for subclasses. This method is called in all constructors and...
Jon Skeet
people
quotationmark

As the comment says, it's an initialization hook for subclasses. Every subclass can override init() appropriately to perform whatever initialization is required in every case, without having to provide another implementation of readObject... more 1/20/2015 7:57:47 AM

people

SQL Syntax error in insert query

Hi to all i am getting error in insert query below is query echo $sql="INSERT INTO event(mode,title,desc,date,status)VALUES('$mode','$title','$desc','$date','$status')"; and...
Jon Skeet
people
quotationmark

The problem is that desc is a reserved word (think of order by), so you need to quota it with backticks when you're using it as a column name. From section 9.2 of the MySQL documentation: Certain objects within MySQL, including... more 1/20/2015 7:22:01 AM

people

Why is this returned array not working?

In this code I'm trying to pass a two dimensional array of chars into cArray and return a one dimensional array of elements that display a string of each row of the two...
Jon Skeet
people
quotationmark

This is the problem: String[] newArray = new String[array2.length]; That's declaring a local variable in the constructor - so you're not assigning a value to the field at all. You just want: newArray = new... more 1/19/2015 10:16:06 PM

people

why the value inside 'if statement' in java cannot be accessed outside of 'if statement'?

following code is giving error message as 'Exception in thread "main" java.lang.Error: Unresolved compilation problem: The local variable answer may not have been...
Jon Skeet
people
quotationmark

Local variables in Java can't be read unless they're definitely assigned - in other words, if the compiler can prove that every way that you can get to the expression that's trying to read the variable will have gone through an assignment... more 1/19/2015 5:46:56 PM

people

Suppress blank namespace in XML element

I have an XML element I am creating. I want Xmlns information to appear in the parent element but no references in any child elements. To acheive this, I am using the following...
Jon Skeet
people
quotationmark

I have an XML element I am creating. I want Xmlns information to appear in the parent element but no references in any child elements That means you want the child elements to be in the same namespace as the default namespace set by... more 1/19/2015 5:38:17 PM

people