Browsing 7239 questions and answers with Jon Skeet

Manual closing inside try with resource

Let's say I'm using a poorly documented third party library, one for which no source code is available. One of the library's methods accepts an InputStream to load various...
Jon Skeet
people
quotationmark

It will entirely depend on the implementation of the resource itself. The try-with-resource statement is "just" syntactic sugar (but oh so sweet) for calling close() within a finally block (and preserving exceptions etc). So long as the... more 1/21/2014 9:54:20 AM

people

Implications of storing a hashed password as an UTF8 string?

I found the following code that is used to hash a password before storing it in an MSSQL database (the column is of type NVARCHAR). string HashPassword(string password) { var...
Jon Skeet
people
quotationmark

You're weakening the security by reducing the number of possible strings that will be encoded. Any time your hash ends up being an invalid UTF-8 sequence, you'll end up with U+FFFD as the output character (the Unicode "replacement"... more 1/21/2014 7:05:42 AM

people

Keypress warning use the new keyword if hiding was intended

I keep getting the following error message at void KeyPress(object sender, KeyPressEventArgs e): Warning 'SpeedyRent.Form2.KeyPress(object, ...
Jon Skeet
people
quotationmark

What is causing it? You're declaring a method with the same name as an event declared in a base class. That hides the event within the derived class, which isn't a good idea in general. Two options: Use new as the compiler... more 1/20/2014 9:29:10 PM

people

Convert float to its binary representation (using MemoryStream?)

I'd like to convert a given float into its binary representation. I tried to write the float value into a MemoryStream, read this MemoryStream byte by byte and convert the bytes...
Jon Skeet
people
quotationmark

You can use BitConverter.GetBytes(float) or use a BinaryWriter wrapping a MemoryStream and use BinaryWriter.Write(float). It's not clear exactly what you did with a MemoryStream before, but you don't want to use StreamWriter - that's for... more 1/20/2014 9:17:35 PM

people

How properly initialize parent and child references between two classes through constructor

I have two classes. First class is Parent, which has a list of objects (Child). Each of the Child has the reference to his Parent class. Question is how to implement this...
Jon Skeet
people
quotationmark

To be immutable and include cyclic references, you'd need something like this: public sealed class Parent { private readonly IEnumerable<Child> children; private readonly string name; // Just for example public... more 1/20/2014 3:50:13 PM

people

Extending java util classes by the book

I am writing a new set of classes to support 2 Key access to maps. Looking at the java.util sources I see that the files there are with ".class" extension, not ".java" and for...
Jon Skeet
people
quotationmark

Looking at the java.util sources I see that the files there are with ".class" extension, not ".java" That just means you're looking at the source file attached to the classes rather than a source file in your project. The source... more 1/20/2014 3:06:26 PM

people

Rename a button with < character in wpf

I have a WPF application in which I try to rename a button like that << Précédent <Button Content="Suivant >>" Background="#FFF9F7F7" Margin="0,0,100,8" ...
Jon Skeet
people
quotationmark

I suspect this is just a matter of XML escaping for <, as you can't use < directly within an attribute value. Try: <Button Content="&lt;&lt; Précédent" ...> ... and please provide more details in your next... more 1/20/2014 2:50:00 PM

people

How to use TimeZoneInfo.ConvertTimeFromUtc in linq to sql?

I have an user table called zeekuser in which I am storing Time Zone information related to user. while retrieving I using below code, var v = (from s in dc.UserWebSites ...
Jon Skeet
people
quotationmark

I doubt that you can do that within the query that's sent to SQL Server. Instead, use AsEnumerable to change context to perform the final step on the .NET side: var query = from s in dc.UserWebSites join zk in dc.ZeekUsers on... more 1/20/2014 2:10:47 PM

people

GUID in JAVA can Contain Space?

I want to know about GUID in JAVA. GUID can contain a white space or not? i am using following Code import java.util.UUID; UUID uuid = UUID.randomUUID(); String...
Jon Skeet
people
quotationmark

No. From the documentation of UUID.toString() The UUID string representation is as described by this BNF: UUID = <time_low> "-" <time_mid> "-" <time_high_and_version>... more 1/20/2014 11:56:30 AM

people

Salesforce datetime issues

I am currently writing a c# .Net application that makes use of the salesforce API. I am sending account objects with datetime fields. my datetime objects are all in this format...
Jon Skeet
people
quotationmark

my datetime objects are all in this format "dd/MM/yyyy HH:mm:ss" No, they're not. At least not if you're talking about .NET DateTime values or database fields. Neither of those implicitly have formats - they're just values. You... more 1/20/2014 11:42:43 AM

people