Browsing 7239 questions and answers with Jon Skeet

Using await on HttpClient in wpf project

I just following a sample in calling HttpClient in sync mode, it works fine in a Console application. However, when I move it to a wpf application, the program hanged without any...
Jon Skeet
people
quotationmark

This line is the problem: string result = x.Result; When you use the Result property, that blocks the current thread until the task has completed. That's a problem when your continuations are meant to run on the same... more 6/5/2016 12:45:17 PM

people

Overriding virtual method

The signature of override method is same as in the original base class System.Object, Since signature only includes the name of method and the types and number of parameter it...
Jon Skeet
people
quotationmark

Why it is necessary to having same return type for overriding a method? In once sense, "because that's what the language specification says". From the C# 5 specification section 10.6.4: A compile-time error occurs unless all of... more 6/5/2016 12:20:06 PM

people

Create static array using Class.forName

In Android there is a undeclared (hidden) class named "android.graphics.FontFamily" and I want to create static array of it. Any thing like this: Class<?> clazz =...
Jon Skeet
people
quotationmark

You should specify the fully-qualified name as specified in the Class documentation. So in your case it would be: Class<?> clazzArray = Class.forName("[Landroid.graphics.FontFamily;"); The [ indicates an array, and then the L... more 6/5/2016 9:04:18 AM

people

How to shuffle specific set of elements in a list?

I have created an ArrayList<MyObjects>. MyObject has an attribute priority, and implements the comparable method, which I have overriden. I want to: Sort...
Jon Skeet
people
quotationmark

Shuffle the list before you sort it. Collections.sort is guaranteed to be a stable sort, so equal elements will be in the same order that they were in the unsorted collection... you just need to make sure that that order is a suitably... more 6/4/2016 7:41:51 PM

people

Lambda implementation to avoid this ForEach Grandad/Dad/Child relation

I'd like to filter a list with child/subchild relation. I've tried with SelectMany/Where/Any to get this right, but the result includes list that don't match the child...
Jon Skeet
people
quotationmark

Well, you can do it all in a single statement: var query = UnfilteredGrandadList.Select(grandad => new Grandad { Id = grandad.Id, // etc DadList = grandad.DadList.Select(dad => new Dad ... more 6/4/2016 4:54:47 PM

people

My own class (List<int>) does not like to intersect. WHY?

I have a class that is derived from List. I am not able to use intersect() on instances of my class. Why? What I have is: class myList : List<int> { ... } What I try to...
Jon Skeet
people
quotationmark

The Intersect extension method doesn't try to return a collection of the same kind as the inputs (e.g. a List<int>). It just returns a sequence implementing IEnumerable<T> for an appropriate T. So in your case you could... more 6/4/2016 2:54:08 PM

people

DateTime.Parse returns wrong value when CultureInfo is used

This is my code: DateTime Now = DateTime.Parse(DateTime.Now.ToString(), new System.Globalization.CultureInfo("fa-ir")); The Geogorian date is: 16/06/2016 The Persian date is:...
Jon Skeet
people
quotationmark

If you're trying to obtain the year, month and day of "now" in the Persian Calendar, you should use the Calendar class: using System; using System.Globalization; public class Test { static void Main() { var now =... more 6/4/2016 1:54:23 PM

people

Returning a list that is filtered based on another list in C#

Im quite new to C# so trying to test a simple string filter but not getting the desired results. This is my test method: [TestMethod] public void Test_ExceptFilter() { ...
Jon Skeet
people
quotationmark

The problem is that you're using Any with a negative condition - which means you'll include the value if there are any words that aren't included in the candidate. Instead, you want to think of it as: Exclude a file the words if any of... more 6/3/2016 7:26:08 AM

people

Equivalent of joda LocalTime getMillisOfDay() in noda

I am porting some code from Java to .NET and looking for a noda-time equivalent of the getMillisOfDay() joda-time method of the LocalTime object. Is there an equivalent one or...
Jon Skeet
people
quotationmark

In Noda Time 1.x, use the LocalTime.TickOfDay property, and then just divide it by NodaConstants.TicksPerMillisecond to get milliseconds: LocalTime localTime = ...; long millis = localTime.TickOfDay / NodaConstants.TicksPerMillisecond; more 6/2/2016 2:10:08 PM

people

parsing xsd from WSDL using LINQ to XML

I am trying to build a dictionary using an XSD file which I get from WSDL definition using LINQ to XML. The nodes which I am trying to parse look something like...
Jon Skeet
people
quotationmark

ToDictionary is your friend here. You can do it all in one statement: var query = xd .Descendants(ns + "element") .Single(element => (string) element.Attribute("name") == "getKeys") .Element(ns + "complexType") ... more 5/30/2016 7:29:00 AM

people