Browsing 7239 questions and answers with Jon Skeet

Java duplicate case label in chars

For unknown reason I've got a duplicate case label error just in two case blocks in this method. This also appears when I separate cases in every single letter (splashing error on...
Jon Skeet
people
quotationmark

The problem is that you're using bitwise | to combine characters - that's not providing multiple cases as I think you expect it to. Instead, it's just taking the Unicode values for the different characters and combining them with a... more 3/27/2014 11:58:51 AM

people

Why can't I create a parameterless subclass constructor when the baseclass has a constructor with a parameter?

I know the following doesn't work, but can you help me understand why? class A { A(int x) { System.out.println("apel constructor A"); } } class B extends A { ...
Jon Skeet
people
quotationmark

Every constructor (other than in Object) must chain to another constructor as the very first thing it does. That's either using this(...) or super(...). If you don't specify anything, the constructor implicitly adds super() to chain to a... more 3/27/2014 11:03:53 AM

people

How to Compare List<> values with a Textbox

i am fetching product id from invoice table in a list CheckProduct(int id): int id = int.Parse(invoice_no.Text); // passing textbox value to list SPBusinesslogic ab = new...
Jon Skeet
people
quotationmark

I suspect you want something like: // TODO: Give your variables more meaningful names throughout... int id = int.Parse(up_invno_txtbox.Text); if (invv.Any(item => item.Id == id)) { ... } else { ... } Obviously adjust the use... more 3/27/2014 10:41:34 AM

people

Strange behavior with actions, local variables and garbage collection in MVVM light Messenger

I am having a really strange problem with the Messenger system in MVVM Light. It's hard to explain, so here is small program that demonstrates the issue: using System; using...
Jon Skeet
people
quotationmark

Well, I now understand why it's happening (I believe, anyway). I've reproduced it in a shorter form which doesn't use lambda expressions, and then I'll explain why the lambdas are important. using System; using... more 3/27/2014 8:38:45 AM

people

where statement doesn't work correctly in c#

I am using MYSQL in my c# app. There are some string values in mysql table and there is a textbox that client can write in that and then I use this statement to show the...
Jon Skeet
people
quotationmark

50 is "bigger" than 400 when you treat them as strings, so I suspect that's what you're doing. First: never, never, never build SQL like this. It's susceptible to SQL injection attacks, it leads to error-prone conversions, and it makes... more 3/27/2014 7:01:40 AM

people

java String and StringBuilder

I am confuse about String and String Builder. Here is my simple code StringBuilder sb1 = new StringBuilder("123"); String s1 = "123"; sb1.append("abc");...
Jon Skeet
people
quotationmark

.But String s1 should be abc123 but it output is abc. Strings are immutable in Java. concat doesn't change the existing string - it returns a new string. So if you use: String result = s1.concat("abc"); then that will be "123abc" -... more 3/27/2014 6:50:01 AM

people

IEnumerable<T> Has Results Until Count() Or Any() Are Called

I'm performance testing variations on Linq extension methods, and I came across an odd situation. When execution returns to the test, calling Count() first will return 1, and...
Jon Skeet
people
quotationmark

Each time you iterate over the result, you're going to call that Where filter... which removes the items from hashset as it goes. So after it's iterated once, hashset will no longer have any of those items, so there'll be nothing left to... more 3/26/2014 6:34:04 PM

people

Removing a charAt[i] from a String

Trying to remove all of the characters that are in String S2 from S1. Example would be: S1 = Mississippi River, S2 = is. Return would be S1 and it would be Mpp Rver. public...
Jon Skeet
people
quotationmark

One simple approach would be something like: public static String removeLetters(String source, String lettersToRemove) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < source.length(); i++) { ... more 3/26/2014 5:38:13 PM

people

read data showing more than one column c#

My Code string s = ""; try { myCon.Open(); myReader = myCommand.ExecuteReader(); while (myReader.Read()) { s += myReader["UserName"] + "\n"; // here is...
Jon Skeet
people
quotationmark

There are various things I would change about this code - returning a stack trace as if it's valid data obtained with no problems is a really bad idea, for example, and you should use a StringBuilder instead of repeated string... more 3/26/2014 4:50:35 PM

people

How to assign DBNull to a primitive type to facilitate Database insert

I have the following line in my code assigning a value to a datatable column. It could be null or a price. double? Price; price = range.Cells[i, j].Value2 == null ? Double.NaN :...
Jon Skeet
people
quotationmark

Using Double.NaN won't help you because NaN is not equal even to itself. It's not clear why you're doing this in two stages though - I'd suggest just: row["Price"] = range.Cells[i, j].Value2 ?? (object) DBNull.Value; more 3/26/2014 4:31:56 PM

people