Browsing 7239 questions and answers with Jon Skeet

Exception says stack is empty when it is not?

I am learning about some advanced collections etc in my book, and have come across stacks. I get the concept but wanted to make a quick program that removes an item from a defined...
Jon Skeet
people
quotationmark

Look at your loop: while(current_index != target) { holding_stack.Push(stack.Pop()); } How do you expect that loop to ever finish? You don't change either target or current_index in the body of the loop... Perhaps you meant to... more 2/5/2015 9:50:55 PM

people

How can I convert a Base64 string to a float array or int array?

I have some code that converts a float[] to a Base64 string: float[] f_elements = <from elsewhere in my code>; byte[] f_vfeat = f_elements.SelectMany(value =>...
Jon Skeet
people
quotationmark

You can use BitConverter.ToInt32 or BitConverter.ToSingle to convert part of an array: byte[] bytes = Convert.FromBase64String(); int[] ints = new int[bytes.Length / 4]; for (int i = 0; i < ints.Length; i++) { ints[i] =... more 2/5/2015 9:40:46 PM

people

Can I create an EXE file using C# with visual web developer express?

The only option I see under C# Windows is "Class Library" to create a DLL. But I don't want a dll. I want an EXE (this time). I'm running Windows 7, btw.
Jon Skeet
people
quotationmark

If you want an executable, that suggests you don't want a web application which is what the Web Developer Express targets. Instead, download and install the "Visual Studio Express 2013 For Windows Desktop" version. That will let you... more 2/5/2015 7:56:26 PM

people

Multiple Sum using Linq (lambda expression)

Its very straight forward, I'm trying to Sum both Amount + Adjusted I'm sure its not the best approach to use. var a1 = context.Employee.Select( a =>...
Jon Skeet
people
quotationmark

There's no need to create any lists (which will pull a load of data from the database, if this is LINQ to SQL or EF) - you can just use: var c1 = context.Employee.Sum(x => x.Amount + x.Adjusted); That's assuming you don't need the... more 2/5/2015 7:32:35 PM

people

What does question mark and dot operator ?. mean in C# 6.0?

With C# 6.0 in the VS2015 preview we have a new operator, ?., which can be used like this: public class A { string PropertyOfA { get; set; } } ... var a = new A(); var foo =...
Jon Skeet
people
quotationmark

It's the null conditional operator. It basically means: "Evaluate the first operand; if that's null, stop, with a result of null. Otherwise, evaluate the second operand (as a member access of the first operand)." In your example, the... more 2/5/2015 7:12:35 PM

people

Load a large text file into a string

I'm looking to load a 150 MB text file into a string. The file is UTF16 encoded, so it will produce a string that's about 150 MB in memory. All the methods I have tried result...
Jon Skeet
people
quotationmark

Both of your attempts so far are treating the file as if it were in UTF-8. In the best case, that's going to take twice as much memory - and it's very likely to be invalid data (as UTF-8), basically. You should try specifying the... more 2/5/2015 5:41:43 PM

people

New object creation concurrent with method call

In the following code, it seems a new object is created while concurrently calling a method (Resize) on that object: Image<Bgr, Byte> img = new Image<Bgr,...
Jon Skeet
people
quotationmark

No, it's not doing it concurrently at all. It creates the object, then calls the method - and then assigns the result of the method call to the variable. So it's equivalent to this: var tmp = new Image<Bgr,... more 2/5/2015 1:38:57 PM

people

issue in display Date in different format with one string value android

Hello friends i have one string value for date like "2015-02-04" and below is my code Date todaysDate = new java.util.Date("2015-02-07"); SimpleDateFormat df = new...
Jon Skeet
people
quotationmark

Simple: don't use the deprecated new Date(String) constructor. Instead, create a SimpleDateFormat with the right format, and use the parse method. DateFormat format = new SimpleDateFormat("yyyy-MM-dd",... more 2/5/2015 11:10:13 AM

people

Convert Joda LocalDate or java.util.Date to LocalDateTime having time at Start of the Day

I am using Joda 2.5 Facing an issue while converting the Joda LocalDate to LocalDateTime. As,I am able to convert LocalDate to DateTime with Time atStartOfDay. I wanted the same...
Jon Skeet
people
quotationmark

Well once you get rid of time zone anomalies, you can probably just assume that every day starts at midnight, so use: LocalDateTime localDateTime = localDate.toLocalDateTime(LocalTime.MIDNIGHT); It's not clear why you wanted to end up... more 2/5/2015 10:31:27 AM

people

Why can't we write Console.Writeline() in if statement?

Why can't we write Console.Writeline() in if condition in C#? But we can write printf() statement in if condition in C?
Jon Skeet
people
quotationmark

In C, the return type of printf is int - the number of characters written. Also in C, an if condition can be any non-void data type, basically. Compare that with C# and .NET, where Console.WriteLine has a return type of void, and the... more 2/5/2015 10:09:40 AM

people