Browsing 7239 questions and answers with Jon Skeet

How to cast List<A> to List<B>

How do I cast List<SelectVacancyDetails_Result> to List< SelectVacancyDetails_ResultExtend> where class SelectVacancyDetails_ResultExtend is inherited from class...
Jon Skeet
people
quotationmark

If all the elements are actually of type SelectVacancyDetails_Result (not SelectVacancyDetails_ResultExtend) then you can't just cast. The simplest approach would be to create a constructor in SelectVacancyDetails_ResultExtend which copied... more 10/2/2015 8:44:39 AM

people

Async Await Loop/Math problems

I'm making a little program to practice with WPF and Async/Await for multithreading, and what the program does is: Find all the prime numbers between two numbers "a" and "b",...
Jon Skeet
people
quotationmark

This has nothing to do with async/await, really. You're calling BeginInvoke here: Prime1.Dispatcher.BeginInvoke( (Action)(()=>{ Prime1.Text += i.ToString() + ", "; })); ... and your lambda expression uses i, which means it will... more 10/1/2015 8:50:42 PM

people

Is there an attribute that is effectively the opposite of ObsoleteAttribute?

In other words, is there an Attribute that marks a segment of code as not too old, but too new and therefore not quite ready for widespread use? If I'd have to create a custom...
Jon Skeet
people
quotationmark

No, there's nothing standardized around this. You might want to consider just not exposing code like that though - or only exposing it in beta builds etc. more 10/1/2015 5:46:33 PM

people

variable n is already defined in java

I am trying to dynamically create objects in java uses an array int number = Integer.parseInt(JOptionPane.showInputDialog("Enter number of objects")); int n[] = new...
Jon Skeet
people
quotationmark

Your code looks like it's trying to declare n[i] as a variable. You don't need to do that, because n is already declared. You just need an assignment to the array element: n[i] = new SomeClass(1, 5, 6); ... but you'll also need to... more 10/1/2015 1:01:20 PM

people

Converting Date to LocalDate returning strange results around 200AD

I'm getting inconsistent results when converting Dates to LocalDates, around the year 200. Using the following code to do the conversion: private LocalDate toLocalDate(Date...
Jon Skeet
people
quotationmark

Stephen has provided an explanation in the comment. Basically, java.util.Date uses a calendar system which cuts over between the Julian calendar system and the Gregorian calendar system in 1582, skipping 10 days. So dates in 1582 or before... more 10/1/2015 8:16:08 AM

people

JsonSerializer failing to write to a GZipStream

I'm trying to serialize very large object directly to a zip stream. I manage to do this by serializing to a file stream in an intermediate step, loading it back and then...
Jon Skeet
people
quotationmark

Rather than flushing the writer, I suggest you close it completely. That way the GZipStream knows there's no more data to write and can add any appropriate checksums or whatever it needs to do. You could either call Close explicitly, or... more 9/30/2015 4:19:40 PM

people

.net Frameworks compatibility

I Create A new application in the framework 4.5 and i have an older application was created in 1.1 framework , i want to call a form that exist in the new application from the old...
Jon Skeet
people
quotationmark

Well, if the old application has been loaded using an older version of .NET that doesn't support the newer assembly, then no. It's a bit like trying to run a 64-bit binary on a 32-bit operating system. The simplest solution would probably... more 9/30/2015 2:54:10 PM

people

Linq searching list of objects

I have this class: public class ExamReviewRequested { public List<ExamReviewRequest> Reviews { get; set;} } It's reviews property has a list of this class: public...
Jon Skeet
people
quotationmark

The problem is that the type of ViewBag.ExamReviews is dynamic, so the compiler doesn't know what to do with your lambda expression. Just cast that part so you can use LINQ on it as normal: var requests =... more 9/30/2015 2:36:01 PM

people

How to create an array of objects of a specific class type

I have a function that returns an Object. The Object can contain an array of primatives or an array of objects. In C# I can create an empty array of objects or primatives using...
Jon Skeet
people
quotationmark

Assuming you only know the element type at execution time, I think you're looking for Array.newInstance. Object intArray = Array.newInstance(int.class, 10); Object stringArray = Array.newInstance(String.class, 10); (That will create an... more 9/30/2015 6:27:29 AM

people

Wagner Fischer algorithm implementation in java

I am trying to implement the Wagner-Fischer algorithm in java using the Wikipedia reference wagner-fischer Java Code: public class StringDistance { public static void...
Jon Skeet
people
quotationmark

Let's get rid of some of the local variables to make it clearer why this is happening: for (j = 1; j <= u.length; j++) { for (i = 1; i <= v.length; i++) { if (u[i - 1] == v[j - 1]) { tracker = 0; }... more 9/30/2015 6:13:35 AM

people