Browsing 7239 questions and answers with Jon Skeet

Why string or object type don't support nullable reference type?

Look into following code block: //Declaring nullable variables. //Valid for int, char, long... Nullable<int> _intVar; Nullable<char>...
Jon Skeet
people
quotationmark

object and string are reference types, so they're already nullable. For example, this is already valid: string x = null; The Nullable<T> generic type is only for cases where T is a non-nullable value type. In the declaration for... more 1/20/2014 11:35:26 AM

people

Omitting access specifier in java

I know that the name of the public class declared in a java file must be same as its file name. But I wonder how this is not giving me a compilation error, rather it is running...
Jon Skeet
people
quotationmark

Yes, that's absolutely fine. Even for public classes, this is a compiler-specific optional restriction. From section 7.6 of the JLS: If and only if packages are stored in a file system (ยง7.2), the host system may choose to enforce the... more 1/20/2014 10:44:35 AM

people

Passing a method's name as a parameter

private void Method1() { //Do something Log("Something","Method1"); } private void Method2() { //Do something Log("Something","Method2"); } private void...
Jon Skeet
people
quotationmark

As of C# 5, this is really easy using caller info attributes: private void Method1() { //Do something Log("Something"); } private void Method2() { //Do something Log("Something"); } private void Log(string message,... more 1/20/2014 9:42:57 AM

people

Oracle connection in ASP.NET

I have a ASP.NET (.NET 4.0) application which implements Rest Services. I am connecting to Oracle in this application. My code works fine as under. Please note its in the...
Jon Skeet
people
quotationmark

This code: OracleConnection m_cnn = new OracleConnection("..."); ... declares a local variable inside the constructor. It's not assigning a value to the instance variable. To do that, you should use: m_cnn = new... more 1/20/2014 9:36:40 AM

people

Get/Set in java and reference

Get / Set methods are there to protect my class fields. But since Java is working with reference my private fields are still getting exposed.. e.g. private Date d; Date...
Jon Skeet
people
quotationmark

Because i dont want to change my Date without using setDate. Then you shouldn't return a reference to a mutable object in your get method. For example: private Date d; Date getDate() { // Return a reference to an independent copy... more 1/20/2014 8:45:21 AM

people

How to get array method from another array method from the other class

My apologize, I have a class on my Project, called test01.java. And i used the library from Tadaki Graphlib contained many class. On of them is Graph.java. Test01.java: ...
Jon Skeet
people
quotationmark

Well you haven't shown where vertexes is initialized (or even declared) in Graph. I suspect it's empty, so when you execute this code: public int[][] getAdjacent() { int n = vertexes.size(); adjacent = new int[n][]; ... ... more 1/20/2014 7:05:41 AM

people

getting error into encrypt and decrypt data using ASP.NET

I am using this code for Encrypt and Dycrpt the data using asp.net . But i am getting the error:-- **Specified initialization vector (IV) does not match the block size for this...
Jon Skeet
people
quotationmark

From the documentation of SymmetricAlgorithm.IV: The size of the IV property must be the same as the BlockSize property divided by 8. I suspect you'll find that rijn.BlockSize is 128, so you should provide a 32-byte IV. (It's not... more 1/20/2014 6:52:21 AM

people

Storing Data in SQLite

Is there a way to store TEXT in SQLite database without SQLite trying to parse it? Ran into a problem where when you store TEXT that is similar to SQLite query, it tries to parse...
Jon Skeet
people
quotationmark

As I suspect, the problem is that you're putting your values directly into the SQL - without even trying to escape them. Don't do that. As well as the problems you're seeing, you've opened yourself up to a SQL injection attack. Use... more 1/19/2014 4:30:19 PM

people

Java: split() method with pipe special character

I have a String = "Hello-new-World". And when i use the split() method with different regex values, it acts differently. String str = "Hello-new-world" String[]...
Jon Skeet
people
quotationmark

Presumably you're splitting on "|" in the second case - and | has a special meaning within regular expressions. If you want to split on the actual pipe character, you should escape it: String[] bits = whole.split(Pattern.quote("|")); more 1/19/2014 9:49:10 AM

people

Javascript either parseInt or + , appending instead of adding

i'm having some trouble with the parseInt function or + operand. I want to take in two numbers, multiply one by a third number and add them together. Instead of adding the...
Jon Skeet
people
quotationmark

I'm not a Javascript expert by any means, but you seem to be ignoring the result of parseInt, instead storing just the result of prompt() in your a, b and t variables. I'd expect this: parseInt(a = prompt('Pay 1'), 10); to be: a =... more 1/19/2014 9:37:21 AM

people