Browsing 15901 questions and answers with Jon Skeet

C# Property with no setter how can it get set from constructor?

How come you can set a get-only auto-property from a constructor? The code below shows how you can set the property from the constructor but using reflection shows that there...
Jon Skeet
people
quotationmark

A read-only automatically-implemented property is converted by the compiler into a read-only field and a read-only property. Assignments to the property in the constructor are compiled as assignments to the underlying field. So your code... more 9/23/2017 4:01:34 PM

people

How to convert a float into time?

As an example lets say I have float total_Time = 228.10803 what I want is to convert total_Time into a time format so it would look like this 00:03:48 how would I do that? I...
Jon Skeet
people
quotationmark

Sounds like you should convert it into a TimeSpan and then format that: using System; class Test { static void Main() { float totalSeconds = 228.10803f; TimeSpan time = TimeSpan.FromSeconds(totalSeconds); ... more 9/23/2017 12:33:24 PM

people

JDBC PreparedStatement Seems to Ignore Placeholder

Given the following code for a PreparedStatement, I use a placeholder (?) to be filled with a String: String sql = "SELECT SUM(Premium), SUM(AgentComm)\n" + "FROM...
Jon Skeet
people
quotationmark

You've got it within double-quotes, which means it isn't a placeholder - it's just part of the value. Beyond that, most SQL databases don't let you use parameters for things like table names and column names - only values can be... more 9/22/2017 5:17:03 PM

people

DateTimeFormatter format with a single pattern letter fails to parse short month name

I see the below error when I run the code listed below : Exception in thread "main" java.time.format.DateTimeParseException: Text 'Thu Sep 21 23:47:03 EDT 2017' could not be...
Jon Skeet
people
quotationmark

You're using M as the month format specifier, but M is a number/text field, so it's expecting a numeric value. I also suspect you mean HH:mm:ss rather than H:m:s for the time part, and yyyy for the year. (The latter is unlikely to be a... more 9/22/2017 4:04:52 PM

people

C# How to convert a struct type list into a string?

I am doing a game in Unity and need help with converting my struct list into a string. My codes below are put inside a class called, MonsterHandler. public enum S_STATE { ...
Jon Skeet
people
quotationmark

I'd first rename the types (and enum values) to follow .NET naming conventions and to indicate that the struct represents a single monster. It's unfortunate IMO that mutable structs are common in Unity, but I'll leave that part aside. I'd... more 9/22/2017 3:32:55 AM

people

Array declaration and assigning values to individual slots of Arrays

I asked this question earlier and got the things clear. However, I have some doubts, explaining below: Let us assume the need is to have an array with 100 elements in this: 1)...
Jon Skeet
people
quotationmark

Those two lines are somewhat equivalent. The first uses auto-boxing. It's actually directly equivalent to: intArr[1] = Integer.valueOf(1); The difference is that this can reuse references to the same Integer object multiple times,... more 9/20/2017 7:07:58 AM

people

Which is better performance wise: Union of several similar lists, or Distinct on a really big list with lots of duplicates?

Little bit of background: I'm making a small app to demonstrate the use of LINQ, so I'm supposed to use mostly LINQ methods. The app is going to show some info about movies and...
Jon Skeet
people
quotationmark

Your second approach needs to internally build a new HashSet for each season, comparing the actors in that season with all the actors we've seen before - I'd expect that to be slower than doing a single pass over all actors, putting them... more 9/19/2017 2:06:37 PM

people

Incorrect decompression of Java Gzip in .NET

I'm trying to repeat in .NET the algorithm that was originally written in Java and I'm having troubles with the GZIP decompression. At the bottom of the post I inserted the hex...
Jon Skeet
people
quotationmark

Now we've got more of the Java code, we can see the problem: you've got an extra layer of serialization around your real data. That has nothing to do with compression really. Here's an example to show what I mean: import... more 9/19/2017 12:18:45 PM

people

Descendants in C# do not give the right value

I am very new in XML using C# i have a XML i need to go through specific children in the parent i need to get the id and the call variables variables i did this but every time...
Jon Skeet
people
quotationmark

The first problem is that you're just calling Descendants("Dialog"), Descendants("CallVariables") etc. Those look for elements in the global namespace - but all the elements you're looking for are actually in a namespace of... more 9/16/2017 9:58:59 AM

people

Unusual Behavior of Abstract Method

I am a java beginner and I was learning to use interfaces. As I have learned that the class which implements an interface must give definition of its abstract methods if it is a...
Jon Skeet
people
quotationmark

You're only recompiling Test.java each time. If you try to recompile everything, you'll see the error again. I don't honestly remember the details about how javac works out what to recompile - whether it checks source vs class file... more 9/14/2017 1:54:19 PM

people