Browsing 7239 questions and answers with Jon Skeet

Why does decompiled code contain a foreach loop?

I've implemented a foreach-loop and a while-loop that should create pretty much the same IL code. The IL code (generated with compiler version 12.0.40629 for C#5) indeed is...
Jon Skeet
people
quotationmark

Here's the code I compiled, which made it slightly easier to look at the differences: using System; using System.Collections.Generic; class Test { static void Main() {} // Just to make it simpler to compile public static void... more 1/8/2016 3:28:33 PM

people

How to hide the parent class method from the child class object?

I want to hide the parent class method for the the child class object. My Circle object display two methods to me when I going to access that methods: Here objShape is the...
Jon Skeet
people
quotationmark

In 2nd image it display the suggestion and I can use that method, but I don't want that suggestion and I don't want use that method with Circle class object. Then you shouldn't make Circle derive from Oval, basically. Don't forget... more 1/8/2016 11:39:50 AM

people

Can't get the literal 'de' from dateFormat. Example: 8 de Enero de 2016

I'm trying to get a date with the following format using the jquery ui datepicker: d de MM de yy. Example: 8 de Enero de 2016 I've try with: dateFormat: 'd \de MM \de...
Jon Skeet
people
quotationmark

The simplest approach is to quote the text with single quotes... but to do that as simply as possible, you should use double quotes for the overall value: dateFormat: "d 'de' MM 'de' yy" more 1/8/2016 10:06:53 AM

people

How to format xml using linq?

Here i am creating a xml using linq and not getting in the required format.Here is my code List<string> listvalue = new...
Jon Skeet
people
quotationmark

It sounds like this is really just a case of wanting to fetch all the URLs (from all the source documents) before you call GenerateXml at all - and remember where each one came from. That's as simple as: var sources = new... more 1/8/2016 7:22:49 AM

people

How to parse an xml file and return default value if no element found

I wrote a simple method in C# to parse a given xml file and return the value of a specific node. It works fine but I'd also like to return a default value if the node is not found...
Jon Skeet
people
quotationmark

Let's start by getting rid of the exception "handling". The node not being found is a "reasonable to expect" error, and one we're going to ensure doesn't result in an exception. Other exceptions - such as the file not being found at all,... more 1/7/2016 5:21:23 PM

people

Calendar get year returns wrong result

I want to create a calendar object and set it to a certain year and a week in that year. Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.WEEK_OF_YEAR,...
Jon Skeet
people
quotationmark

I suspect that the calendar is trying to use the current day-of-week (it's Thursday today) in the first week of 2016. Now, looking at your calendar settings, you've got firstDayOfWeek=1 (so weeks run Sunday to Saturday) and... more 1/7/2016 10:38:10 AM

people

Subtract one day in XMLGregorianCalendar

How to subtract one day in XMLGregorianCalendar? Also while subtracting how to cope up with following problems : it does not goes to a negative value in case of first day of the...
Jon Skeet
people
quotationmark

Just convert to a normal GregorianCalendar, do the arithmetic there, then convert back: GregorianCalendar calendar = xmlCalendar.toGregorianCalendar(); calendar.add(Calendar.DAY_OF_MONTH, -1); xmlCalendar =... more 1/7/2016 8:16:23 AM

people

Avoiding duplicate code in Linq Select method

I have some stupid situation where I can't find simple and elegant solution for annoying problem. I writing asp.net application with simple UI for querying database based on user...
Jon Skeet
people
quotationmark

I'd use: Expression<Func<Result, Foo>> conversion = result => { ... }; First case: var result = queryable.Select(conversion); Second case: var result = queryable.Select(entity => entity.Result) ... more 1/7/2016 7:56:52 AM

people

Using LINQ to retrieve value from XML (Multiple selection)

I'm trying to convert this VB.Net LINQ to C# LINQ. Basically, what the end solution is trying to achieve is to to take in an XML file; see snippet: <BasicFee> ...
Jon Skeet
people
quotationmark

As noted in comments, your VB example wouldn't work either, but it's pretty simple to do in both languages. You need to distinguish between names and values, and exactly how your filtering works: var example = root.Elements("BasicFee") ... more 1/7/2016 6:43:41 AM

people

Convert URI to String taking only host, port and path

I have object of java.net.URI type and I want to convert it to String representation, but I'm interested only in the following components: host port path I don't want to have...
Jon Skeet
people
quotationmark

You could fairly easily build a new URI: URI partial = new URI( null, // scheme null, // user info uri.getHost(), uri.getPort(), uri.getPath(), null, // query null); // fragment String text =... more 1/6/2016 5:44:29 PM

people