Browse by Tags

Tagged Content List
  • Blog Post: Why is deriving a public class from an internal class illegal?

    In C# it is illegal to declare a class D whose base class B is in any way less accessible than D. I'm occasionally asked why that is. There are a number of reasons; today I'll start with a very specific scenario and then talk about a general philosophy. Suppose you and your coworker Alice are developing...
  • Blog Post: It's still essential!

    I am pleased to announce that Essential C# 5.0 by Mark Michaelis, and, new for this edition, yours truly , is available for pre-order now . It will be in stores in early December. As long-time readers of this blog know, I was one of the technical editors for Essential C# 4.0 and Essential C# 3.0 . Mark...
  • Blog Post: Dynamic contagion, part two

    Last time I discussed how "dynamic" tends to spread through a program like a virus : if an expression of dynamic type "touches" another expression then that other expression often also becomes of dynamic type. Today I want to describe one of the least well understood aspects of method type inference...
  • Blog Post: Dynamic contagion, part one

    Suppose you're an epidemiologist modeling the potential spread of a highly infectious disease. The straightforward way to model such a series of unfortunate events is to assume that the population can be divided into three sets: the definitely infected, the definitely healthy, and the possibly infected...
  • Blog Post: A method group of one

    I'm implementing the semantic analysis of dynamic expressions in Roslyn this week, so I'm fielding a lot of questions within the team on the design of the dynamic feature of C# 4. A question I get fairly frequently in this space is as follows: public class Alpha { public int Foo(string x) { ... } } ...
  • Blog Post: Is C# a strongly typed or a weakly typed language?

    Presented as a dialogue, as is my wont! Is C# a strongly typed or a weakly typed language? Yes. That is unhelpful. I don't doubt it. Interestingly, if you rephrased the question as an "and" question, the answer would be the same. What? You mean, is C# a strongly typed and a weakly typed...
  • Blog Post: How do we ensure that method type inference terminates?

    I missed the party. I was all set to be on that massive wave of announcements about TypeScript , and then a family emergency kept me away from computers from Thursday of last week until just now, and I did not get my article in the queue. Suffice to say that I am SUPER EXCITED about TypeScript. Long...
  • Blog Post: An "is" operator puzzle, part two

    As I said last time , that was a pretty easy puzzle: either FooBar, or the type of local variable x, can be a type parameter. That is: void M<FooBar>() { int x = 0; bool b = x is FooBar; // legal, true if FooBar is int. FooBar fb = (FooBar)x; // illegal } or struct FooBar { /* ... */ } void M<X>...
  • Blog Post: An "is" operator puzzle, part one

    It is possible for a program with some local variable x: bool b = x is FooBar; to assign true to b at runtime, even though there is no conversion, implicit or explicit, from x to FooBar allowed by the compiler! That is, FooBar foobar = (FooBar)x; would not be allowed by the compiler in that same program...
  • Blog Post: Out parameters and LINQ do not mix

    I am back from my annual vacation in beautiful southwestern Ontario; before I get into the subject of today's post, check out this shot I took with my Windows Phone camera from the plane on the trip home. We are at 37000 feet, just outside of Billings, Montana, a few minutes before sunset: The whole...
  • Blog Post: Should C# warn on null dereference?

    As you probably know, the C# compiler does flow analysis on constants for the purposes of finding unreachable code. In this method the statement with the calls is known to be unreachable, and the compiler warns about it. const object x = null; void Foo() { if (x != null) { Console.WriteLine(x.GetHashCode...
  • Blog Post: When is a cast not a cast?

    I'm asked a lot of questions about conversion logic in C#, which is not that surprising. Conversions are common, and the rules are pretty complicated. Here's some code I was asked about recently; I've stripped it down to its essence for clarity: class C<T> {} class D { public static C<U>...
  • Blog Post: Foolish consistency is foolish

    Once again today's posting is presented as a dialogue, as is my wont. Why is var sometimes required on an implicitly-typed local variable and sometimes illegal on an implicitly typed local variable? That's a good question but can you make it more precise? Start by listing the situations in which an implicitly...
  • Blog Post: Eric Rambles On About C#, Again

    Rachel Roumeliotis, who amongst other things edits C# books for O'Reilly, recently did an interview with me where I ramble on about async/await, Roslyn, performance analysis as an engineering discipline, and some broad-strokes ideas for future language research areas. If you have sixteen minutes to burn...
  • Blog Post: Implementation-defined behaviour

    As I've mentioned several times on this blog before , C# has been carefully designed to eliminate some of the "undefined behaviour" and "implementation-defined behaviour" that you see in languages like C and C++. But I'm getting ahead of myself; I should probably start by making a few definitions. Traditionally...
  • Blog Post: Announcing Microsoft Roslyn June 2012 CTP

    Good afternoon all, I am happy to announce that we are releasing a second Community Technology Preview release of Roslyn, the project I actually work on, today. I am super excited! So, let's cut to the chase. Key facts: Roslyn is a library of code analysis APIs useful for building compilers, development...
  • Blog Post: Past performance is no guarantee of future results

    Before I get started today, a couple housekeeping notes. First off, sorry for no blog the last three weeks; I have been crazy busy adding features to the Roslyn C# semantic analyzer. More on that in an upcoming episode. Second, check out the snazzy new Developer Tools blog aggregation page ; it's one...
  • Blog Post: null is not false, part three

    Returning now to the subject at hand: we would like to allow user-defined "overloads" of the & and | operators in C#, and if we are going to have & and | be overloadable, it seems desirable to have && and || be overloadable too. But now we have a big design problem. We typically overload...
  • Blog Post: null is not false, part two

    In Raymond Smullyan 's delightful books about the Island of Knights and Knaves -- where, you'll recall, knights make only true statements and knaves make only false statements -- the knights and knaves are of course clever literary devices to explore problems in deductive (*) logic. Smullyan, to my recollection...
  • Blog Post: null is not false

    The way you typically represent a "missing" or "invalid" value in C# is to use the "null" value of the type. Every reference type has a "null" value; that is, the reference that does not actually refer to anything. And every "normal" value type has a corresponding "nullable" value type which has a null...
  • Blog Post: Why not automatically infer constraints?

    UPDATE: Whoops! I accidentally set a draft of this article to automatically publish on a day that I was away on vacation. The fact that it was (1) not purple and (2) introduced the topic and then stopped in mid-sentence were both clues that this was an unfinished edit. Sorry about that; I thought I had...
  • Blog Post: Why are local variables definitely assigned in unreachable statements?

    You're probably all familiar with the feature of C# which disallows reading from a local variable before it has been "definitely assigned": void M() { int x; if (Q()) x = 123; if (R()) Console.WriteLine(x); // illegal! } This is illegal because there is a path through the code which, if taken, results...
  • Blog Post: The C# 5.0 beta release is now available

    I am super excited to announce that the beta release of Visual Studio version 11 (which includes the .NET CLR version 4.5, Visual Basic version 11 and C# version 5) is available for download right now. As you know if you've been following our CTP releases, in C# and VB we've greatly improved the ease...
  • Blog Post: The Solution To The Simple Puzzle

    The first time I ran my histogram visualizer I asked for a Cauchy distribution with a minimum of -10 and a maximum of 10, and of course I got a graph that looks much like the one from my article of last week: Looks perfectly reasonable; I guess my program is correct right out of the gate, because I am...
  • Blog Post: A Simple Puzzle

    My original version of the histogram-generating code that I whipped up for the previous episode of FAIC contained a subtle bug. Can you spot it without going back and reading the corrected code? private static int[] CreateHistogram(IEnumerable<double> data, int buckets, double min, double max)...
Page 1 of 14 (343 items) 12345»