Browsing 7239 questions and answers with Jon Skeet

Write signed byte array to a stream

I want to write signed byte array sbyte[] to a stream. I know that Stream.Write accepts only unsigned byte[], so I could convert sbyte[] to byte[] prior to passing it to the...
Jon Skeet
people
quotationmark

You can use the fact that the CLR allows you to convert between byte[] and sbyte[] "for free" even though C# doesn't: sbyte[] data = ...; byte[] equivalentData = (byte[]) (object) data; // Then write equivalentData to the stream Note... more 8/6/2015 10:50:43 AM

people

The type of the expression must be an array type but it resolved to String1

Hello I am very new to java and I want to use a constructor, pass it with a parameter from another class. But eclipse is giving me an error "The type of the expression must be an...
Jon Skeet
people
quotationmark

Well, there are two problems here. First, you've got: this.Type = Type.split("\\."); ... which uses Type instead of type. Next, you're using type[0] which is referring to the parameter called type, not the field. You could fix it... more 8/6/2015 10:34:02 AM

people

C# import XML file character error

I would like to query a pdb file (in XML format) and store the relevant information in another xml file. I've been around some tutorials and managed to do it in simplier...
Jon Skeet
people
quotationmark

You've misunderstood the meaning of an element that looks like this: <PDBx:atom_siteCategory> That's an element with a local name of atom_siteCategory in the namespace with the URI of "http://pdbml.pdb.org/schema/pdbx-v40.xsd" as... more 8/6/2015 8:40:19 AM

people

Convert base64 byte array to an image

I have a form bean with attributes id, desc and imageByteArray. Struts action gets executed and it redirects to a JSP where i want to access these bean attributes like id, desc...
Jon Skeet
people
quotationmark

DoubleMalt's answer (accepted at the time of writing) is unfortunate, because it's sort of using two wrongs to make a right. It doesn't help that Apache Commons Codec makes it so easy to do the wrong thing :( Base64 is fundamentally an... more 8/6/2015 7:16:40 AM

people

Visual C# Missing partial modifier

I get an error saying "Missing partial modifier on declaration of type 'projectName.Main'; another partial declaration of this type exists. From what i can read about this error,...
Jon Skeet
people
quotationmark

Assuming this is a Windows Forms app, the problem is that the Visual Studio WinForms designer has created another file (e.g. Main.designer.cs) with: public partial class Main : Form to contain designer-generated code. Your partial... more 8/5/2015 12:15:53 PM

people

C# Garbage Collector, Threading and Compiler/Jitter optimization

Let's assume that our program has a central point (an instance of a Document class), where all kinds of information are referenced. Now we have two threads. Both threads have...
Jon Skeet
people
quotationmark

Is it possible that the jitter might optimize the code of thread 1 that way that tempParams is not a memory address but a CPU register? I suspect that's possible - but that won't stop the garbage collector from treating it as a use of... more 8/5/2015 11:52:35 AM

people

Performance Improvement Tips for ForEach loop in C#?

I need to optimize the below foreach loop. The foreach loop is taken more time to get the unique items. Instead can the FilterItems be converted into a list collection. If so...
Jon Skeet
people
quotationmark

It's unclear what you mean by "converting FilterItems into a list" when we don't know anything about it, but you could definitely consider sorting after you've got all the items, rather than as you go: var strings =... more 8/5/2015 11:01:29 AM

people

Is there An Efficient way of combining two collections?

I have classes as follows: public class Root { public int Id {get;set;} public string PlayerName{get;set;} } public class Scores:Root { public int GameT{get;set;} ...
Jon Skeet
people
quotationmark

It looks like you just want a LINQ inner join: var query = from score in scores join exp in experiences on score.Id equals exp.Id select new Total { Id = score.Id, Name =... more 8/5/2015 8:15:41 AM

people

read() method of BufferedReader and InputStreamReader

Why do I get an exception when parsing the characters to integer using the read() method instead of readLine() of BufferedReader. I tried using this code below: BufferedReader...
Jon Skeet
people
quotationmark

Reader.read() just returns a single character - but as an int, so you can tell if you've reached the end of the data. Now there isn't any Integer.parseInt(int) method, which is why the calling is failing - there isn't even... more 8/5/2015 6:13:46 AM

people

How to print a parametrized SQL query?

How can I get a String with a parametrized SQL query, once parameters inserted ?
Jon Skeet
people
quotationmark

I think you're assuming that the parameter values will be injected into the SQL and that what ends up being sent to the server is a single string. There's no reason why that needs to be the case - although it could be in some... more 8/4/2015 7:43:00 PM

people