Browsing 7239 questions and answers with Jon Skeet

Looking for an interface/abstract but with methods returning different types

I am looking for a design pattern for a base class that forces all derived classes to implement all base class methods, while the methods in the derived classes have different...
Jon Skeet
people
quotationmark

It sounds like you just need to make it generic: public interface MemoryObject<T> { T FromMemory { get; } //... other properties and methods } public class MemoryObjectA : MemoryObject<List<string>> { ...... more 12/11/2013 5:09:53 PM

people

"AWT EventQueue 0" java.lang.NullPointerException error on MySQL JDBC java project

I'm new to ubuntu, and in the last days I installed eclipse and lamp for working with a project that was already running on windows7. The problem is that the same string of...
Jon Skeet
people
quotationmark

Okay, so now that you've shown the line that's actually blowing up: stmSql = f.conn.prepareStatement("select * from film"); And f.conn is null. That's because when you assign a value to f.conn, if anything goes wrong you print out an... more 12/11/2013 3:23:24 PM

people

Loop through object properties without reflection

I have class MyModel and some object of MyModel. I need for-loop or foreach properties of object without reflection. How implemented? Class example: public class MyModel { ...
Jon Skeet
people
quotationmark

I would strongly suggest that you take two actions: Create a new type to encapsulate the combination of TypeName, AttrType, AttrValue Change your model to contain a collection of that class rather than several separate properties. At... more 12/11/2013 2:51:18 PM

people

Declaring a 2D array without knowing its size in C#

I would like to use a 2-D array but I can't know its size in advance. So my question is: how to declare it? And then how to add values into it? String[,] tabConfig = new...
Jon Skeet
people
quotationmark

So my question is: how to declare it? You can't. All arrays in .NET are fixed size: you can't create an array instance without knowing the size. It looks to me like you should have a List<T> - and I'd actually create a class... more 12/11/2013 2:12:27 PM

people

Code throwing exception. Where is the error?

I'm learning C and C#, this question is for C#. I can't see where and what is throwing the exception. Any help much appreciated? Here is the code: private static void...
Jon Skeet
people
quotationmark

I can't immediately tell you where the problem is, but I can tell you how to find out. First, remove this catch block (and indeed the try clause): catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } That is... more 12/11/2013 12:54:34 PM

people

The scope of variable in inner anonymous method

See the code public class Test { public static void Main() { Test t = new Test(); var AnonymousMethod = t.OuterMethod(); ...
Jon Skeet
people
quotationmark

The scope of the variable (the region of program text within which it is possible to refer to it without qualification) remains the same. The "lifetime" of the variable is effectively extended: the lambda expression captures the variable.... more 12/11/2013 11:23:35 AM

people

Why do we need to implement interfaces to provide certain functionality instead of just defining the methods without implementing the interface?

An IComparable class provides a CompareTo method that compares two objects and determines their ordering, an IEquatable class provides an Equals method that determines whether an...
Jon Skeet
people
quotationmark

Why do we need to implement these interfaces to provide this functionality? So that other code can be written in terms of the interface, and work with objects of types which implement the interface without knowing about the specific... more 12/11/2013 9:29:05 AM

people

Caliburn Micro > Composing Views from multiple Views/UserControls/CustomControls

How is it possible to re-use and compose parts in CM managed windows? I have found posts regarding using two UserControls to bind to the same ViewModel, but not so much if I want...
Jon Skeet
people
quotationmark

I'm not going to claim to be an expert in CM by any means, but I've had reasonable success with a simple "benchmark explorer" I've been writing. That uses a single "shell view" that composes two other views, each with its own ViewModel.... more 12/11/2013 7:04:39 AM

people

How can I suppress the null output of a BufferReader?

Using the following code to split the output of a reader into strings which are then used in a constructor. However when the bufferreader reaches the end of the stream it outputs...
Jon Skeet
people
quotationmark

buff is never going to be null - it's the return value of readLine which is null when you reach the end of the data. That's what you need to check, typically with code which assigns the value to a variable and checks it in one go: String... more 12/10/2013 6:44:06 PM

people

inOrderIterator method cannot be applied to BinaryTreeNode<T>

Working on an InOrderIterator traversal method. I understand how to do this recursively but I keep getting this complier error. inOrderIterator() in...
Jon Skeet
people
quotationmark

Look at your method declaration: public ArrayList<T> inOrderIterator() It doesn't have any parameters. But look how you're trying to invoke it: inOrderIterator(currentNode.getRightChild()); ... you're specifying an argument.... more 12/10/2013 6:19:51 PM

people