Blogs

BROWSE: Most Recent | Popular Tags |

Tags > csharp

Functions are values: explore C# lambda types in Visual Studio

By Andrew Stellman
April 9, 2011

I love that a college professor of mine from long ago, Bob Harper, is tackling the tricky issue of how to teach students about the nature of functions in his new Existential Type blog. His post got me thinking about how you'd go about teaching this concept to a learner—specifically, in my case, a C# learner. I've given it a bit of thought, and here's what I've come up with.

Understanding C#: Nullable Types

By Andrew Stellman
November 7, 2010

Every C# developer knows how to work with value types like int, double, boolean, char, and DateTime. They're really useful, but they have one flaw: they can't be set to null. Luckily, C# and .NET give you a very useful tool to for this: nullable types. You can use a nullable type any place that you need a variable that can either have a value or be null. This seems like a simple thing, but it turns out to be a highly flexible tool that can help make your programs more robust. In this tutorial, I'll show you the basics of nullable types, and give you a quick example of a program that uses them to handle unpredictable user input.

Understanding C#: Simple LINQ to XML examples (tutorial)

By Andrew Stellman
October 16, 2010

XML is one of the most popular formats for files and data streams that need to represent complex data. The .NET Framework gives you some really powerful tools for creating, loading, and saving XML files. And once you've got your hands on XML data, you can use LINQ to query anything from data that you created to an RSS feed. In this post, I'll show you two simple LINQ to XML tutorial style examples that highlight basic patterns that you can use to create or query XML data using LINQ to XML.

Understanding C#: Equality, IEquatable, and Equals()

By Andrew Stellman
September 29, 2010

What does it really mean for two objects to be equal? How can you tell if object #1 is equal to object #2? Do you compare all of their properties? What about private properties or fields? Is it possible for two objects to have exactly the same state, but to not be equal? It's more complex than it seems. In this post, I'll detangle some of those ideas, and show you how to use IEquatable, the Equals() and GetHashCode() methods, and overloading the == and =! operators so that you can compare objects in your own code.

Understanding C#: Raising events using a temporary variable

By Andrew Stellman
September 10, 2010

A lot of C# developers notice that there's something odd about how we normally raise events in C#. We're always told to set a temporary variable equal to the event first, and then raise the event using that variable. It looks very strange—how could that variable do anything at all? But it turns out that there's a very good reason for using the temporary variable, and understanding that reason can help you become a better C# developer. This post shows a quick example of why you need that variable.

Build HTML documentation for your C# code with Sandcastle in under 5 minutes

By Andrew Stellman
September 3, 2010

If you've ever used a library that has accurate MSDN-style API documentation, you know how useful it can be. There are lots of ways to create HTML documentation. But the easiest way that I've found is to use Sandcastle. It's an open source documentation generator from Microsoft that reads your assemblies (DLL or EXE files) and their XML Comments and automatically generates HTML documentation. Sandcastle is a very flexible tool, which means it's also a very complex tool. Luckily, there's a companion tool, Sandcastle Help File Builder, that makes it really easy to get up and running with Sandcastle in minutes.

Understanding C#: String.Intern makes strings interesting

By Andrew Stellman
August 22, 2010

One of the first things a new C# developer learns is how to work with strings. We teach the basics of strings early on in Head First C#, and it's the same way with practically every other C# book I own. So it shouldn't be surprising that novice and intermediate C# developers feel like they've got a pretty good handle on strings. But strings are more interesting than they appear. One of the more interesting aspects of strings in C# and .NET is String.Intern, and understanding it can help make you a better C# developer. In this post, I'll go through a quick String.Intern tutorial to show you how it works.

Understanding C#: Use System.Console to build text-mode games

By Andrew Stellman
August 17, 2010

I'm a sucker for an old-school text-mode console game. Text-mode games rendered their "graphics" by drawing text characters at different positions on the screen using 16 background and foreground colors. They're also easier than ever to build in C# and .NET, thanks to theSystem.Console class, which lets you position the cursor, do animation by moving blocks of the buffer, use colors and special characters, and handle input from the user. In this tutorial post, I'll walk you through all of the tools you need to create a retro MS-DOS style text-mode video game, including a complete game that you can build yourself.

Essential developer skills: Refactoring in Visual Studio 2010

By Andrew Stellman
August 8, 2010

If you've been reading my blog posts, you know that I try to help novice and intermediate C# programmers improve their skills, and help progress along the developer career path. I think this goes beyond simply getting better at programming C# and .NET. There are additional skills that, in my opinion, really make a difference in your ability to code. It's possible to become an advanced programmer without them, but it's a lot easier with them. Refactoring is one of those skills, and I think that any C# developer—even a novice one—can benefit from it. If you're a C# developer looking to take the next step on your career path and you don't refactor your code regularly, this is a great starting point to help move to the next level.

Understanding C#: Explore types using the Type class and GetType()

By Andrew Stellman
August 5, 2010

One of the most powerful aspects of the C# programming language is its rich type system. But until you've got some experience building programs, it's difficult to appreciate it--in fact, it can be a little baffling at first. But we want to give you at least a taste of how types work in C# and .NET. This tutorial helps get you started exploring the type system. In it, you'll create a console application that gives you an introduction to some of the tools you have at your disposal to work with types.

Understanding C#: Namespaces and assemblies (a quick .NET tutorial)

By Andrew Stellman
July 12, 2010

I recently had a reader e-mail me with a question about assemblies and namespaces because he had trouble on a job interview that asked a lot of interview questions about .NET assemblies. Luckily, I had a good answer for him that covered the .NET assembly basics: what an assembly is, how to create a class assembly DLL, how to use that assembly DLL in another program, how to use the Add References window in Visual Studio, and where Visual Studio gets its assemblies to list in that window. At the end of Head First C#, we have a section about it that also uses the IDE as a teaching tool to explore how assemblies work. I thought it did a good job of answering that reader's .NET assembly interview questions, and I hope it will help some others get a handle on how namespaces and assemblies work. It makes for a good .NET assembly tutorial that shows the basics of assemblies work in C# programs. So here it is, adapted to blog post format.

Understanding C#: Using BackgroundWorker to make your UI responsive

By Andrew Stellman
June 28, 2010

Someone once told me that he could tell a form was built by a novice C# developer if it stopped responding when he pressed a button. I'm not 100% sure I agree, but I definitely think that an intermediate or advanced C# developer should be able to build a form that stays responsive even when the program is doing something CPU intensive. Luckily, C# and .NET give us a simple way to do that using the BackgroundWorker class. Not only is it a great tool to let your programs do more than one thing at once, it's a good way for novice and intermediate C# developers to get started with threading.

Understanding C#: XML Comments

By Andrew Stellman
June 14, 2010

As C# developers get more experienced, there are a lot of things they pick up along the way that are really useful and important to know, even if they aren't necessarily directly code-related. One of those topics is XML comments, and I've been surprised at how many developers -- even really experienced ones -- don't use them, or even know about them. They're really useful, and they can help you build better software, even if they don't actually change the way your programs behave.

Understanding C#: Why make things private?

By Andrew Stellman
January 23, 2010

Andrew Stellman is the author of Head First C# and other books from O'Reilly. A reader on the Head First C# forum posted a question. It's actually a really good question, one that a lot of developers ask once they...

Understanding C#: Using virtual and override

By Andrew Stellman
October 27, 2009

One of our Head First C# readers posted a question on the book's forum: I don't understanding why I need to add 'virtual' keyword and 'override' keyword to make Penguin Fly() override Bird Fly(). [page 226] I think public class...

Getting Java, C# and Perl to speak the same language (with JSON)

By Andrew Stellman
October 4, 2009

I've been thinking a lot about architecture lately. It's partially because Jenny and I are going to do our Beautiful Teams talk at the ITARC 2009 conference next week. But it's also because I've been writing a lot of code...


1 to 16 of 16
The Watering Hole