Browsing 7239 questions and answers with Jon Skeet

Locale two argument construct in action

Here's my code snippet for Locale classes used for date formatting: List<Locale> locales = new ArrayList<>(8); locales.add(new Locale("en")); locales.add(new...
Jon Skeet
people
quotationmark

You happen to have picked countries which all have the same format. However, that's not always the case. Here's a different example: import java.util.*; import java.text.*; class Test { public static void main(String[] args) { ... more 4/19/2016 6:48:46 PM

people

error while returning byte array

I am using the below code public byte[] encrypt(byte[] unencryptedString,String k)throws Exception { String encryptedString = null; String k1 = String.format("%024d",...
Jon Skeet
people
quotationmark

Contrary to the other answers, I wouldn't change your code to return null if you fail to encrypt the text - I would let that failure bubble up as an exception. I wouldn't declare that your method can throw Exception either - I'd specify... more 4/19/2016 4:03:04 PM

people

C# Tasks.ContinueWith

Im trying to execute two different tasks from async methods but my second task only should start where the first ends. I've tryed to use ContinueWith but with no success. This is...
Jon Skeet
people
quotationmark

my second task only should start where the first ends Then you should genuinely wait for it to finish. Currently, you're not doing so. You're waiting for the DoFirstThing method to return, but it will do so before it finishes awaiting... more 4/19/2016 12:00:13 PM

people

Why base64 decodes strings are different in Python2.7 and in Linux

I have following commands in linux as, base64 encoded string 'rITqHhVbOjGIWelaJbg==' in file test64.dat. used commands - # base64 -d -i test64.dat >> test.dat # echo "IV="...
Jon Skeet
people
quotationmark

There are two issues here: 1) Your input is invalid. It has too many = at the end, so the Linux output includes "base64: invalid input" which you're merrily decoding as hex afterwards. 2) hexdump isn't giving you the format you really... more 4/18/2016 7:14:32 AM

people

Dynamically adding properties to an Object from an existing static object in C#

In my ASP .Net Web API Application while making the DB calls, some properties are needed to be added to the Model Class which already have some existing properties. I understand...
Jon Skeet
people
quotationmark

Well you could just create a new ExpandoObject and use reflection to populate it with the properties from the existing object: using System; using System.Collections.Generic; using System.Dynamic; using System.Linq; using... more 4/18/2016 6:08:33 AM

people

How to set the output of a JAVAC compiled file

My previous question asked how to compile files with the command JAVAC. I still don't know how to set the output file of the compiled data.
Jon Skeet
people
quotationmark

The output of javac is always classfiles, and the name of the file matches the name of the class contained within it. (A source file with multiple classes in will result in multiple output files.) If you use the -d command line option,... more 4/17/2016 9:36:34 PM

people

Does making singleton class sealed really help in achieving goal of singleton pattern C# Static Initialization (A thread safe solution)

I know other threads exist regarding this question but I couldn't find satisfactory answer for this. Why singleton class needs to be sealed in C# ? (To clarify my question)Does...
Jon Skeet
people
quotationmark

Simply put: if anyone can derive from it, there can be multiple instances. So you definitely need some way of preventing arbitrary derivation. Now you can simply rely on a private constructor to prevent subclassing instead (and you need... more 4/17/2016 7:27:01 PM

people

C# How would set the output of this to a string?

So this is a section of code for my tcp client. This part is to convert the bytes recieved into characters. However, i would like to put some logic to it and to do that i need to...
Jon Skeet
people
quotationmark

As per comments, if you want to decode a byte array in a particular encoding, just use Encoding.GetString. For example: string text = Encoding.ASCII.GetString(bb, 0, k); (Note that ASCII is rarely a good choice if the text is meant to... more 4/17/2016 4:34:12 PM

people

An array initializer of the length of 2 is expected

I'm trying to get an AI to learn the and function but this 3d array is not working out int[, ,] inputs = { { { 0, 0 }, {0} }, { { 0, 1 }, {...
Jon Skeet
people
quotationmark

You've declared a rectangular array - although I suppose "cuboid" array would be more appropriate in this case. But you have to make each "sub-array" initializer the same length. To continue the geometric metaphor, every column has to be... more 4/16/2016 6:41:42 PM

people

Combining Method hiding and method overriding in C#

I just could not find a satisfactory explanation for this. So I thought it would help to post this at SO. What happens when we combine method hiding and overriding in C# ? For...
Jon Skeet
people
quotationmark

But here how can even a BaseClassA reference variable point to DerivedClassC object and it prints DerivedClassB's output ? The code calls the method which is declared by BaseClassA but overridden by DerivedClassB. The method declared... more 4/16/2016 4:54:20 PM

people