Browsing 7239 questions and answers with Jon Skeet

C# Dynamic List to Static List

From the documentation of the Event Log Class the EventLogEntryCollection is a dynamic list of event log entries. It recommends that the Count property is used directly instead of...
Jon Skeet
people
quotationmark

Is there a way to store this list statically so the count does not change? It sounds like you want something like: List<EventLogEntry> entries = eventLogEntries.Cast<EventLogEntry>().ToList(); That will fetch all the... more 5/21/2014 3:33:18 PM

people

Cannot Resolve Method when using generics

I am trying to implment a tree for my project. This tree will contain nodes which are different board states after some move. Right now my project is structured like so: ...
Jon Skeet
people
quotationmark

This is the problem: public static class Node<Board> That's declaring a generic class called Node, and Board is a type parameter. Within Node, the identifier Board refers to the type parameter called Board, not the type Board... more 5/21/2014 3:13:34 PM

people

Java charAt getting wrong character

I am trying to make an algorithm that will do the following: 64 797 7 === 79 that will take 7, multiply it by 7, and then write the last digit of the answer down and then...
Jon Skeet
people
quotationmark

I strongly suspect that the problem is the type of tens. You haven't shown this in your code, but I suspect it's int. So this line: tens = (upper*7+"").charAt(0); takes the first character from a string, and then stores it in an int.... more 5/21/2014 3:08:00 PM

people

Check if object is null without using ==

In my program, I have objects derived from Dictionary. I need to check if 2 objects are equal, so I made an overload operator ==. But at a later point, I need to check if a...
Jon Skeet
people
quotationmark

In my program, I have objects derived from Dictionary. I would strongly reconsider deriving from Dictionary in the first place. That's very rarely a good idea. Favour composition over inheritance in general, and think very carefully... more 5/21/2014 2:39:56 PM

people

What is the java equivalent of VBA's "With" statement

In VB / VBA you can do something like this: With person .Name = "John" .Age = 32 End With But in java I can't figure out how or if that functionality exists. Everything...
Jon Skeet
people
quotationmark

If it doesn't exists, is there at least some methodology to cut down on the repetition? Nope, not really - not unless you control the type. If you do control the type, you can make the set methods return this, allowing you to chain... more 5/21/2014 1:46:09 PM

people

LINQ lambda expression, finding a child object where property is == X

Need help with a LINQ lambda expression in C#. So let me explain the structure of my object. RootObject is a collection(custom class with multiple properties) that has many...
Jon Skeet
people
quotationmark

It sounds like you want something like: // Parse the target ID *once* rather than all the time... var targetId = int.Parse(IDToFind); var playerRound = RootObject.SelectMany(i => i.Items) .SelectMany(x =>... more 5/21/2014 1:04:42 PM

people

Finding the list of common objects between two lists

I have list of objects of a class for example: class MyClass { string id, string name, string lastname } so for example: List<MyClass> myClassList; and also I...
Jon Skeet
people
quotationmark

So you're looking to find all the elements in myClassList where myIdList contains the ID? That suggests: var query = myClassList.Where(c => myIdList.Contains(c.id)); Note that if you could use a HashSet<string> instead of a... more 5/21/2014 12:31:05 PM

people

Found weird behavior with Joda API

I started looking at joda API for handling timezone related issues for my web application. I found very weird behavior while doing so. I hope there must be some workaround. here...
Jon Skeet
people
quotationmark

Given that you want hours and minutes (an Hours object can only hold an integer number of hours) you probably want: Period period = new Period(utcDateTime.toLocalDateTime(), currentDateTime.toLocalDateTime(), ... more 5/21/2014 12:04:19 PM

people

Getting error while using a throws clause with an overriding method in java?

I am getting a error when i am using a throw clause with the method demo().And i want to know that what are the limitations of using throws in inheritance. The error is:...
Jon Skeet
people
quotationmark

ClassNotFoundException is a checked exception - and you can't declare that a method override will throw any checked exceptions that the method it's overriding doesn't declare. From section 8.4.8.3 of the JLS: A method that overrides... more 5/21/2014 10:14:23 AM

people

Converted word document (from Windows 1252 to UTF 8) not displaying characters correctly

I have a Windows-1252 word document that I want to convert to UTF-8. I need to do this to correctly convert the doc file to a pdf. This is how I currently do it: Path source =...
Jon Skeet
people
quotationmark

I have a Windows-1252 word document That's not a text file. Word documents are basically binary data - open it up with a plain text editor and you'll see all kinds of gibberish. You may see some text in there as well, but basically... more 5/21/2014 9:46:49 AM

people