Browsing 7239 questions and answers with Jon Skeet

Why is my method not found by the compiler?

I have a class "Worker" with an entry method internal void Run() { //do stuff... } I have a subclass for testing ("TestWorker:Worker") with an entry method internal void...
Jon Skeet
people
quotationmark

The problem is that the compile-time type of worker is just Worker - and there isn't a Worker.Run method accepting a parameter. This has nothing to do with delegates per se - you wouldn't be able to call worker.Run("foo"); either. The... more 12/13/2013 10:34:58 AM

people

Why aren't the calls in main sequential?

I was going through some simple examples on threading/synchronizing from a book that claims the use of synchronized will allow access to the method by one thread being called on...
Jon Skeet
people
quotationmark

Why is the third call consistently calling call before the second? It's not doing so consistently - it's doing so about 90% of the time. Basically, synchronization isn't guaranteed to be first-in, first-out... and there's no... more 12/13/2013 9:47:30 AM

people

c# using indexofany for the decimal point and restricting only to one decimal point

`private void Dot_Click_1(object sender, EventArgs e) { if (NumBox1.Text.IndexOfAny(char['.']) { }` I think...
Jon Skeet
people
quotationmark

It's not clear why you've got char['.'] at all, or what you expect it to mean. I suspect you just want the character literal '.' and use IndexOf. else if (NumBox1.Text.IndexOf('.') == -1 && ...) You only want to use IndexOfAny... more 12/13/2013 7:53:47 AM

people

LinkedList in c# xamarin

I have a linked list which contains views. I want to assign the last view element in the list to another view variable. This is what I did :- private readonly...
Jon Skeet
people
quotationmark

This isn't a Xamarin issue. Your code is just broken. Both RemoveFirst and RemoveLast are void methods - they don't return the first/last elements, they just remove them. You'll need to use the First and Last properties, then remove the... more 12/13/2013 7:38:13 AM

people

Send non printing character binary sms in android

I am developing a crypted sms app, I am crypting the sms to 3DES and I am trying to send the byte array result to the other phone using SmsManager.sendDataMessage but I am not...
Jon Skeet
people
quotationmark

If you're fundamentally trying to send arbitrary bytes through a text-based interface, the safest way to do so is to use base-64. There's a Base64 class in Android which makes this very easy. Admittedly this means the size is inflated a... more 12/13/2013 6:45:46 AM

people

The property Count from ICollection<T> is still around for backward compatibility?

Previous Context To understand what I'm questioning, see first the question "Why does .Count work without parentheses?" In that question is discussed, Why exists Count...
Jon Skeet
people
quotationmark

No, it's around so that a collection can return how many elements there are directly, without having to iterate over it. Enumerable.Count() has an optimization such that if the collection implements ICollection<T>, it will use the... more 12/12/2013 6:22:47 PM

people

Java ArrayList issue

I need some help with a line of code in a program that I am writing. I feel like it's going to be some stupid mistake but I just can't seem to figure out what it...
Jon Skeet
people
quotationmark

Why won't the line "customSequences.get(......." work? You're trying to assign a value to the result of a method call. That's what doesn't work. You can only use the assignment operator with a variable. I suspect you... more 12/12/2013 6:15:26 PM

people

FileWriter stops unexpectedly

I am trying to use XLS2CSV to convert an Excel file to a csv text file. I modified the existing class slightly to change PrintStream to Writer so I could write to a file using...
Jon Skeet
people
quotationmark

You're not closing the writer, which means there's data still in the buffer. You should close it (and all the other streams etc) in finally blocks, or use a try-with-resources statement if you're using Java 7. Also note that the way... more 12/12/2013 4:45:43 PM

people

Exception in thread "AWT EventQueue 0" java.lang.NullPointerException Java GUI Error

I am trying to design a calculator in java. My code isn't finished but I have designed a GUI, which works except for when i try to actually calculate the result. When i press "="...
Jon Skeet
people
quotationmark

You're never initializing calcOperands - so on line 60, when you use: calcOperands.add(operand); ... calcOperands is still null, causing the exception. It looks like you have the same problem for your other ArrayList variables. You can... more 12/12/2013 4:18:46 PM

people

How to combine IEnumerable<string[]>

I'm trying to work on improving my LINQ skills, while at the same time beginning with Code Kata. Right now, I'm trying to improve my work on this Kata by using LINQ instead of...
Jon Skeet
people
quotationmark

Fortunately it's really simple - you just want SelectMany, which acts as a "flatten" operation: IEnumerable<string> strings = list.SelectMany(x => x); Or avoid Select to start with, and go straight to... more 12/12/2013 1:55:42 PM

people