Browsing 7239 questions and answers with Jon Skeet

Generic type function (property)

I'm trying to return a T type value. public T this[int index] { get { if (typeof(T) == typeof(int)) return (T) dynEx[index].Int; ...
Jon Skeet
people
quotationmark

In order to cast to int, you'll need to cast the result to object first, potentially boxing. It's annoying, but unfortunately it's a limitation of C# generics - for good reasons that escape me right now, unfortunately. So you want: public... more 5/20/2017 8:32:31 PM

people

pass byte[] , file parameter to a method java

I m confused to how to pass byte array and file to a method in Java : when I call enregistre method : enregistre(img3File, file3) and enregistre(img4File, file4) ...
Jon Skeet
people
quotationmark

Look at what your enregistre method does: BufferedOutputStream stream; stream = new BufferedOutputStream(new FileOutputStream(new File("ben1"))); stream.write(imgFile); stream.close(); If you call that method multiple times, it will... more 5/20/2017 5:00:11 PM

people

Avoiding skipping a row By next() Method of ResultSet

This is a simple code print some rows from a Database. but When I execute this nothing is print on screen. I figured that the problem is rs.next() method is skipping a row. So How...
Jon Skeet
people
quotationmark

First, stop building SQL like that - use parameterized SQL and a PreparedStatement. Your current code is vulnerable to SQL injection attacks. Basically, don't call rs.next() twice in a row (first in the if then in the while)... you can... more 5/20/2017 4:18:16 PM

people

.NET Standard vs .NET Core

I have read about the difference between .NET Standard and .NET Core, but I really don't know what the difference is, or when to choose a .NET Standard library project and when to...
Jon Skeet
people
quotationmark

.NET Core is an implementation of .NET Standard. It's available on multiple operating systems, but that's not the same thing - there are other implementations of .NET Standard as well. So if you create a .NET Core library, it will have... more 5/20/2017 11:41:26 AM

people

Unchecked assignment for 'java.util.ArrayList'

I get the warning: Unchecked assignment for 'java.util.ArrayList' to 'java.util.ArrayList < com.test.mytest ' for: private ArrayList<LocoList> myLocations = new...
Jon Skeet
people
quotationmark

You want new ArrayList<>(); so that you use the right generic type. At the moment you're using the raw type on the right hand side of =. So you want: private ArrayList<LocoList> myLocations = new ArrayList<>(); Or just... more 5/19/2017 8:00:08 PM

people

MSBuildWorkspace Get Embedded Resource Files

I'm trying to get out all embedded resource files from a solution using Roslyn and MSBuild Api. private async Task<Document> CheckConstForLocalization(Document document,...
Jon Skeet
people
quotationmark

You can't, at the moment. It isn't supported by the API. (I was researching this just yesterday.) There's a feature request to support it which you might like to support and subscribe to, but I don't believe there's any way of doing this... more 5/19/2017 7:45:36 PM

people

C# Array Within Array of Structs Losing Contents

I'm just returning back to C# after an extended period of C++ and Qt. I'm currently stumped by what I would have thought to be a very simple problem. I have a struct: struct...
Jon Skeet
people
quotationmark

It had occurred to me that the struct was being passed into the RenderFontGlyph function by-value rather than by-ref but this also makes no difference! Well yes, it does. You're creating a copy of the struct, and passing that into... more 5/19/2017 7:08:28 PM

people

Constructor Enum error

public enum ProductCategory { FOOD, BEVERAGE, DEFAULT; private final String label; private ProductCategory(String label){ this.label = label; } public String getLabel(){ ...
Jon Skeet
people
quotationmark

The only constructor you've currently got requires a string to be passed in - but all the enum values (FOOD, BEVERAGE, DEFAULT) don't specify strings, so they can't call the constructor. Two options: Add a parameterless... more 5/19/2017 5:18:51 PM

people

Java number precision in Javascript

I have the following code in Java that convert Hex values to Long numbers, in the example I used the value: 'B4EEB49B04C0' public static long HexStr2Long(String value) { ...
Jon Skeet
people
quotationmark

1463925582232864000 is the nearest 64-bit IEEE-754 floating point number to 1463925582232863984. Numbers in Javascript are (at the moment - I believe this is changing) always 64-bit IEEE-754 floating point numbers. Basically, in order to... more 5/18/2017 4:03:51 PM

people

Date difference from Noda Time is correct?

DateTime dtStart = new DateTime(2015,7,28); LocalDate ldtStart = LocalDate.FromDateTime(dtStart); DateTime dtEnd = new DateTime(2017, 2, 1); LocalDate ldtEnd =...
Jon Skeet
people
quotationmark

"More accurate" requires a specification of how you want to compute the difference. There's no single right answer here. As documented, Noda Time works element-wise. So if you add 1 year, 6 months and 4 days to 28th July 2015 you... more 5/18/2017 5:57:24 AM

people