Browsing 7239 questions and answers with Jon Skeet

GroupBy Date in LINQ C#

I am trying to GROUPBY Date in a LINQ Query and display the output as shown below startdates: [ startdate: “4/1/2014”, users: [ {userId, …}, {userId, …} ], startdate:...
Jon Skeet
people
quotationmark

The problem is your selection part, here: .Select(y => new { startdates = y.Select(k => new {startdate = (k.startDate.Month.ToString() + "/" + k.startDate.Day.ToString() + "/" + k.startDate.Year.ToString()), users = y.Select(z... more 4/8/2014 5:54:41 AM

people

error on Decryption: javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher

Here it is program for encryption and Decryption using DES. program is working when passing the output of encryption directly for decryption. but when taking input from user in...
Jon Skeet
people
quotationmark

I can't easily tell whether this is all that's wrong, but this is definitely wrong: byte[] encryptedData = encryptData("Confidential data"); //String from user String s=encryptedData.toString();//String input to decrypt From user byte[]... more 4/7/2014 9:40:13 PM

people

c# remove special charachters from string

I have the following string which represents an xml: string xmlStr7 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Response...
Jon Skeet
people
quotationmark

Your string starts with a byte order mark (U+FEFF). Ideally, you shouldn't get that into your string to start with, but if you do have it, you should just strip it: string text = ...; if (text.StartsWith("\ufeff")) { text =... more 4/7/2014 8:04:11 PM

people

How to mark a part of c# code to be compiled if particular library is referenced and ignored if it isn't?

I would like to build a version of an application of mine without use of some features provided by a class library but avoid deleting the actual code (the code using the feature...
Jon Skeet
people
quotationmark

You can use preprocessor directives to control this - not on the basis of your references, but on the basis of symbols: #if USE_SOME_LIBRARY // Code that uses the library #endif Then just make sure that you define USE_SOME_LIBRARY in... more 4/7/2014 7:49:00 PM

people

stunned at readline socket java

I need to make a "static" chat, when my client say "PAPO", my server need to print PAPO and send PEPO to client print. But im having problem at my readLine() on server, simple...
Jon Skeet
people
quotationmark

Look at what you're writing from the client: saida.write("PAPO"); That doesn't have a line break, so the server doesn't know whether there's more text coming in the same line. Also, because you haven't flushed your writer, it may be... more 4/7/2014 7:35:28 PM

people

End of stream reached when InputStream.read(array) does not return array.length?

I'm having these lines of code: final int packetLength = 64 //just some constant InputStream in = socket.getInputStream(); byte[] packet = new byte[packetLength]; int read =...
Jon Skeet
people
quotationmark

No, you can't be sure of that. InputStream doesn't block until it's read all the data you've requested - it blocks until it's read some data. (The default implementation of InputStream will read until it's read everything it can, but... more 4/7/2014 7:00:32 PM

people

Dont understand the exception handeling in the case of changing interfaces as mentioned in Refactoring book by Fowler

I'm reading the Fowler book on Refactoring. In chapter 2 in the changing interfaces section. I don't understand this passage: There is one particular area with problems in...
Jon Skeet
people
quotationmark

Suppose you currently have: public interface Foo { void bar(); } You cannot later evolve this to: public interface Foo { void bar() throws SomeException; } (where SomeException is a checked exception) because code that... more 4/7/2014 6:13:13 PM

people

Is it thread safe to read a property from an instantiated object?

Can I safely read a IsBusy boolean property for an instantiated singleton from multiple threads without causing any thread-safety issues, or am I already in dangerous waters?
Jon Skeet
people
quotationmark

Unless you have any memory barriers, you're potentially in dangerous waters, if the value can ever change. Let's take the singleton part of this out of the equation, as it's not particularly relevant. Consider this simple example: // Not... more 4/7/2014 4:10:08 PM

people

convert a DateTime to Oracle DateTime

Im looking to convert a DateTime to an Oracle DateTime (to pass to an Oracle stored proc.) I was thinking of using what's below in a general conversions class I have but I'm not...
Jon Skeet
people
quotationmark

Well that operator means you can just cast: DateTime input = new DateTime(...); OracleDateTime result = (OracleDateTime) input; ... It's not clear what you mean by "how to return the converted date" - it's not like you'd want a method... more 4/7/2014 1:08:16 PM

people

Memory assigned to strings

I know that strings in C# are immutable i.e. when I change the value of a string variable a new string variable with the same name is created with the new value and the older one...
Jon Skeet
people
quotationmark

if a new string is created, then is it created in the same memory location? No, a separate string object is created, in a separate bit of memory. You're then replacing the value of s1 with a reference to the newly-created string.... more 4/7/2014 11:56:51 AM

people