Browsing 7239 questions and answers with Jon Skeet

Error 404 from Google Search API

I'm getting a 404 error from the code below. I'm running Visual C# Express 2010. The query portion of the string is: ...
Jon Skeet
people
quotationmark

You're escaping far too much. You should only escape the query value - not the key/value pair separators. So the URL should be something like: string url = string.Format( ... more 4/24/2014 6:24:08 AM

people

Why there is no access modifier named "Visible"?

In OO languages like C++, Java or C#, there are access modifiers like public, private, protected. Some languages have other modifiers like internal. All of them specifies who can...
Jon Skeet
people
quotationmark

Your suggestion would encourage the implementation detail of how the state is represented within the class to be made public. Using one level of indirection - properties - allows you to separate out the public API of a type from its... more 4/24/2014 5:51:56 AM

people

Why is a bool's default val (false) not recognized?

With this code: bool successfulSend; const string quote = "\""; string keepPrinterOn = string.Format("! U1 setvar {0}power.dtr_power_off{0} {0}off{0}", quote); string...
Jon Skeet
people
quotationmark

But isn't false the default value of bool[ean]s? For fields (instance variables and static variables), yes. But local variables don't have default values, regardless of their type. They have to be definitely assigned before they're... more 4/23/2014 4:35:34 PM

people

Writing in a log with StreamWriter and Trace Listeners is very slow

I'm facing a problem here, i'm in internship right now, and I have to modify a given program. I had some lag issue, and i finally found the problem : the log writer ... The more...
Jon Skeet
people
quotationmark

This is probably the issue: Trace.Listeners.Add(new TextWriterTraceListener(swLog)); Every time you add a log entry, you're adding an extra trace listener... so the first time, you'll get one log entry. The second time, you'll get two... more 4/23/2014 12:57:07 PM

people

groupCount() in java.util.regex.Matcher always returns 0

I've trying to count how many matching patterns are there in a string. I'm new to using java.util.regex and I was planning on using matcher.groupCount() to get the number of...
Jon Skeet
people
quotationmark

You haven't specified any capturing groups. If you change your pattern like this: Pattern pattern = Pattern.compile("(@)"); then you'll have a capturing group - but it will still only return 1, as each match only has a single group.... more 4/23/2014 12:36:33 PM

people

Lambda expression to delegate instance or expression tree?

After reading this related answer -still I have a question A lambda expression is an unnamed method written in place of a delegate instance. The compiler immediately converts...
Jon Skeet
people
quotationmark

It converts to whichever type you've asked it to. For example: Func<int> del = () => 0; // Conversion to delegate Expression<Func<int>> expression = () => 0; // Conversion to expression tree In your case, you're... more 4/23/2014 10:57:37 AM

people

Implements an interface that return a generic type

I saw these: Java generics interface implementation java method generics implementing interface I do understand why the compilator complains. Anyway, if we only use the...
Jon Skeet
people
quotationmark

For a generic method, the caller can specify the type argument - so I should be able to use: Connection foo = new IoConnectionStub(); Integer x = foo.<Integer>getVersion(); That's clearly not going to work in your case. It sounds... more 4/23/2014 8:37:44 AM

people

Sort by second field if the first field is null

How to convert this in C# linq/lambda query select * from meetings order by ISNULL(ActualStartDate, StartDate) desc so far I tried this but seems like it doesn't...
Jon Skeet
people
quotationmark

I suspect you want: var sorted = meetings.OrderByDescending(m => m.ActualStartDate ?? m.StartDate); Note that calling the method won't change meetings - you need to use the return value which will be a sorted sequence of results.... more 4/23/2014 6:06:04 AM

people

Video Sitemap colon in name using LINQ to XML

I am trying to make a video sitemap for video website. But I am facing a XMLExecption "The ':' character, hexadecimal value 0x3A, cannot be included in a name." This is because of...
Jon Skeet
people
quotationmark

video here is the alias for a namespace. As per the example: <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"> <url> ... more 4/22/2014 3:01:14 PM

people

How to display decimal numbers in Java?

I'm using float to display decimal numbers, but sometimes it doesn't display correct result. For example, for 6.2/1000 the result is 0.0061999997. I know why is this happening,...
Jon Skeet
people
quotationmark

First, you need to understand that this isn't just a display issue - if you want to avoid displaying incorrect values, it helps to have the right values to start with. You should use BigDecimal instead of float. That stores the value as... more 4/22/2014 2:28:50 PM

people