Browsing 7239 questions and answers with Jon Skeet

How does .NET framework low level APIs work?

One of the questions that i always faced was the implementation of .NET Framework class libraries. I know some of the methods original implementation: For example :...
Jon Skeet
people
quotationmark

Can you do exact same thing without using that method? Actually Nope. You absolutely can. Here's a really inefficient way of doing it - which doesn't consider overflow, invalid input or negative numbers, but demonstrates the general... more 12/30/2014 8:26:24 PM

people

Recurring calender invitation was showing one hour off after DST starts

I am sending a request from my .net application(C#) to create recurring meeting invite in outlook. the meeting invite was showing one hour off during day light saving (march 8th...
Jon Skeet
people
quotationmark

This is the problem: DTSTART: starttime.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z") DTEND: Endtime.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z") You're explicitly specifying the start and end times as UTC, and you're never... more 12/30/2014 8:12:57 PM

people

HttpServletRequest getting request parameters separated by # instead of?

I am trying to get the Query String Parameters in the controller from the following URL using javax.servlet.http.HttpServletRequest...
Jon Skeet
people
quotationmark

Those aren't query parameters. They're the fragment of the URI - and that isn't sent to the server at all. It can only be used client-side. From RFC 3986: A fragment identifier component is indicated by the presence of a number sign... more 12/30/2014 7:50:58 PM

people

cast on object of type superclass returns object of type subclass in java

I have implemented the following code in order to understand the difference between static and dynamic binding: class A { int met(A a) { return 0; } int...
Jon Skeet
people
quotationmark

So, let's look at the call: ((A)this).met((A)this); That's equivalent to: A target = this; A argument = this; target.met(argument); So, for the last line, the compiler looks up the signature based on the compile-time types involved -... more 12/30/2014 7:17:08 PM

people

Is there a discontinuity over year end in DateTime

I was hoping to write down a countdown timer for a New Year's party tomorrow, but I seem to have encountered an issue with subtracting two DateTimes from eachother. My app seems...
Jon Skeet
people
quotationmark

You're not constructing the dates you think you are. These lines: var later = new DateTime(2015-01-01); var now = new DateTime(2014-12-31); are equivalent to: var later = new DateTime(2013); var now = new DateTime(1972); After all,... more 12/30/2014 6:45:56 PM

people

Get week number for the given date c#

I have tried searching for a solution which gives the correct week number for the date value. link1, link2,link3 Followed the methods in the above links, but for the date...
Jon Skeet
people
quotationmark

If you're looking for the ISO-8601 week-of-week-year, you could use my Noda Time project: var date = new LocalDate(2014, 12, 30); var week = date.WeekOfWeekYear; // 1 var weekYear = date.WeekYear; // 2015 You can get a LocalDate from a... more 12/30/2014 5:54:42 PM

people

Can't add values to List (Count is always 1) C#

Many times I had to create lists of structures to store my data in C#. But this time, I have a problem, I can't seem to be able to add values to my list. I don't quite understand...
Jon Skeet
people
quotationmark

On the overload constructor I have a message that shows the count of the list values every time a new one is added and guess value is always 1 and I just don't understand why. That's because each time you create a new instance of mng... more 12/30/2014 4:43:55 PM

people

Why C# requires two double quotes to print " in case of verbatim string?

If I store a verbatim string, string s=@""Hello""; it should hypothetically parse the string and print "Hello" (taking the " character as a part of the string) but in actual...
Jon Skeet
people
quotationmark

So technically, string s=@""Hello""; should print "Hello" No, that would just be invalid. The compiler should - and does - obey the rules of the language specification. Within a verbatim string literal, double-quotes must be doubled... more 12/30/2014 1:02:41 PM

people

Anonymous function and local variables

Say you have a button on your form. You attached an anonymous function to button's Click event: void Test() { int x = 10; btn.Click += (sender, e) => {...
Jon Skeet
people
quotationmark

Half of the point of anonymous functions are that they can capture the context in which they're specified. It's extremely convenient to be able to do so - that's the "why" part. The way the compiler does this is to create a new class in... more 12/30/2014 8:19:15 AM

people

Why can't we just use arrays instead of varargs?

I just came across varargs while learning android(doInBackground(Type... params)) ,SO posts clarified the use of it My question is why can't we just use Arrays instead of...
Jon Skeet
people
quotationmark

The only difference between foo(String... strings) and foo(String[] strings) is for the calling code. Consider this call: foo("a", "b"); That's valid with the first declaration of foo, and the compiler will emit code to create an... more 12/29/2014 12:51:17 PM

people