Browsing 7239 questions and answers with Jon Skeet

How do you derive from an Abstract Class having overloaded Constructors

I have an Abstract Class having 2 overloaded constructors. I want to require all derived classes to implement both constructors as both variations support some of the virtual...
Jon Skeet
people
quotationmark

You don't inherit constructors at all. You declare whichever constructors you want, and make sure that each one chains appropriately, either to a base class constructor, or to another constructor in the same class. So for example, you... more 8/1/2014 6:40:29 PM

people

How to Get UTC DateTime

How can i get UTC DateTime from the following code, Right now with this line of code m getting an output like this Fri Dec 31 05:30:00 IST 9999. Is this output is correct. I mean...
Jon Skeet
people
quotationmark

Well, the output is correct in that it's what I'd expect for midnight UTC when you're running on a system in IST. Date.toString() always uses your system local time zone - because it doesn't have any other information. A Calendar knows its... more 8/1/2014 3:13:56 PM

people

Outputstream is an abstract class so we cannot instantiate it.Why then a default constructor is provided for Outputstream class?

here is the link for API documentation of Outputstream abstract class .You will find a default constructor http://docs.oracle.com/javase/7/docs/api/java/io/OutputStream.html#OutputStream%28%29
Jon Skeet
people
quotationmark

The class has to have at least one constructor, because all Java classes have constructors. Additionally, subclasses will have to chain to it - so it's got to be at least protected accessibility. The constructor doesn't need to do... more 8/1/2014 1:56:30 PM

people

Serial Ports There is an error in XML document (5, 3870)

Here I have a class I've created for the purpose of sending text-files and images over a serial port: public class SendItem { private byte[] bytes; private string...
Jon Skeet
people
quotationmark

It may or may not be the whole problem, but this is definitely a problem: byte[] buffer = stream.GetBuffer(); That's quite possibly returning more data than you want - because it's not limiting itself to the length of the stream.... more 7/31/2014 9:30:07 PM

people

Super Simple Escape Sequence [Beginner]

I'm trying to replace "C:\FREQ\" with a whitespace. String trimmed = files[i].toString().replace("C:\FREQ\", ""); But eclipse gives an error on the "C:\FREQ\" , saying Invalid...
Jon Skeet
people
quotationmark

You need to escape the backslashes: String trimmed = files[i].toString().replace("C:\\FREQ\\", ""); Backslashes within Java text literals (String or char) are used for escape sequences such as \t (tab), \n (line feed) etc. To get an... more 7/31/2014 6:51:17 PM

people

Can I cast event args inside the called function in C# instead of defining delegates?

I have an event: public event RoutedEventHandler ActionEvent; I have a superclass: internal class MyEventArgs : RoutedEventArgs { public enum SomeAction { ...
Jon Skeet
people
quotationmark

You can do this - but then you're really being very specific in your implementation, without being specific in the type system. Why not just use EventHandler<TEventArgs>? public event EventHandler<MyEventArgs>... more 7/31/2014 2:27:29 PM

people

How to use LINQ to find all items in list which have the most members in another list?

Given: class Item { public int[] SomeMembers { get; set; } } var items = new [] { new Item { SomeMembers = new [] { 1, 2 } }, //0 new Item { SomeMembers = new [] {...
Jon Skeet
people
quotationmark

This can be written pretty easily: var result = items.Where(item => item.SomeMembers.Count(secondList.Contains) * 2 >= item.SomeMembers.Length); Or possibly (I can never guess whether... more 7/31/2014 2:03:16 PM

people

Confusion regarding the initial position of the pointer in a list iterated by the Iterator interface

where is the initial index of the pointer to the list should it not be the first item of the list. does the next method (1)returns the next element of the and points to...
Jon Skeet
people
quotationmark

where is the initial index of the pointer to the list should it not be the first item of the list No. It is before the first item of the list. You only get to the first item when you call next() for the first time. In fact, it's... more 7/31/2014 1:58:54 PM

people

Get the boolean from Func<T, bool>

I want to get the boolean value from the following fluent function: public IGridWithOptions<T> CursorPointerWhen(Func<T, bool> propertySpecifier) { bool r = ???? ...
Jon Skeet
people
quotationmark

You'll need to have a T value in order to call the delegate: public IGridWithOptions<T> CursorPointerWhen(Func<T, bool> propertySpecifier) { T input = GetInputFromSomewhere(); bool r = propertySpecifier(input); ... more 7/31/2014 1:52:28 PM

people

Use instance's method in generic method

My code goes like this: public T ReadState<T>(string file_path) { string file_content = ...read file..from file_path... T state = ...xml deserialize... ...
Jon Skeet
people
quotationmark

Of course, they all implementing the SetSomething() method Then you should tell the compiler that: Create an interface with the SetSomething() method Make all the relevant types implement the interface Constrain T to implement that... more 7/31/2014 1:49:43 PM

people