Browsing 7239 questions and answers with Jon Skeet

float to string with no decimal value in C#

This is how I get previous greatest ID from my datasource and plus one to this value . string _fID = (float.Parse("." + DBContext.Employees.OrderByDescending(x => ...
Jon Skeet
people
quotationmark

I would suggest you stop using floating point types at all. Just use integers, as that's basically what you've got. (It's a shame that your data type is textual when you're logically just using integers.) string currentHighest =... more 9/23/2013 6:26:14 AM

people

Explicit specification of Arraylists

Is the explicit specification of array lists considered as a bad practice since Java7? Why is it unneccessary from this version? List<String> foo = new...
Jon Skeet
people
quotationmark

Is the explicit specification of array lists considered as a bad practice since Java7? It's not "bad practice" - it's just a little more longwinded than it might be. The two statements have exactly the same effect, so there's no... more 9/23/2013 6:02:09 AM

people

C# Obtaining data from WebRequest not returning values

I have the following C# method that accepts a URL as an input and returns the text data that exists at that location: public string GetWebData(string uri) { string response =...
Jon Skeet
people
quotationmark

You're returning response immediately - even though the callback which assigns a useful value to response will only fire later. Do you understand how BeginGetResponse works? It would be worth studying the documentation and examples... more 9/22/2013 4:30:27 PM

people

add the results of all linq statements to one big enumeration

How can i do this code in one linq statement? i.e. add the results of all linq statements to one big enumeration List<Type> alltypes = new List<Type>(); var...
Jon Skeet
people
quotationmark

It sounds like you want: var allTypes = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(assembly => assembly.GetTypes()) .ToList(); Use SelectMany when one "input" item (an assembly... more 9/21/2013 8:14:04 PM

people

Variable not initialized

I'm writing a program for the "University Book Store" for a class. And I feel like everything should be working, but for publishingPrice and markup, I'm getting a "Variable not...
Jon Skeet
people
quotationmark

You only assign a value to markup within if statements. The compiler doesn't keep track of what's feasible, and whether you've covered all cases... so the variable still isn't definitely assigned as far as the compiler is concerned. The... more 9/21/2013 8:09:53 PM

people

FirstOrDefault() method of System.linq.Enumerable namespace throwing NullReferenceException

I have a static readonly collection of user defined object type which is initialized like below. private static readonly List<MyClass> obj = new...
Jon Skeet
people
quotationmark

I would like to know why 'ac' object is NULL here, even if we the collection is empty, as per MSDN FirstOrDefault should return NULL for reference types if it does't find the match. This shows that GetMyClasses() returns a collection... more 9/21/2013 6:50:26 PM

people

Read all standard input into a Java byte array

What's the simplest way in modern Java (using only the standard libraries) to read all of standard input until EOF into a byte array, preferably without having to provide that...
Jon Skeet
people
quotationmark

I'd use Guava and its ByteStreams.toByteArray method: byte[] data = ByteStreams.toByteArray(System.in); Without using any 3rd party libraries, I'd use a ByteArrayOutputStream and a temporary buffer: ByteArrayOutputStream baos = new... more 9/21/2013 6:43:59 PM

people

Difference between Date.parse() and .getTime()

What's the main difference between: dt = new Date(); ms = Date.parse(dt); and dt = new Date(); ms = dt.getTime(); they have the same output, but what the difference? and...
Jon Skeet
people
quotationmark

The first version converts a Date to a string and parses it, which is a pretty pointless thing to do - and in some cases could lose information, I suspect. (Imagine during a DST transition, when the clock goes back - the same local times... more 9/21/2013 6:13:30 PM

people

Java, where is the unwanted data in the tcp output coming from?

I'm trying to send some bytes of data to login to an embedded device over my lan but when I send the data there is 2 bytes being appended to the tcp stream. What is causing...
Jon Skeet
people
quotationmark

It's println which is adding the \r\n, but you've got fundamental problems here beyond that. You're treating binary data as if it's text. That will bite you sooner or later. If you're trying to work with binary data, use OutputStream and... more 9/21/2013 3:51:45 PM

people

NullPointer when passing String Array between two activities in Android

I am trying to send an array of Strings which basically include a path of a file on the device. First the user Selects Picture 1 and then Select Picture 2. Once the user completes...
Jon Skeet
people
quotationmark

This code is clearly broken: if (_imagesPath == null) { for (int i = 0; i <= 1; i++) { _imagesPath[i] = _userImagePath[i]; _originalBitmaps[i] = BitmapFactory.decodeFile(_imagesPath[i]); } } If you get into... more 9/21/2013 3:44:25 PM

people