Chuck Sphar

Chuck Sphar is a programmer and former senior technical writer for the Visual C++ product group at Microsoft.

Articles & Books From Chuck Sphar

Article / Updated 02-01-2018
Everyone has special needs, and those needs change as time progresses. Microsoft is aware of this. Someone with perfect eyesight in the morning might suffer from tired eyes in the afternoon. Many web users have some sort of special need all the time. Whether the need is intermittent or constant, making your site accessible means making it easy for everyone to use.
Article / Updated 02-01-2018
When you define a new variable, you can use the dynamic keyword, and C# will let you make assumptions about the members of the variable. For example, if you want to declare a new Course object, you do it like this:Course newCourse = new Course();newCourse.Schedule();This is, of course, assuming that you have a Course class defined somewhere else in your program, like this:class Course {public void Schedule(){//Something fancy here}}But what if you don't know what class the new object will be?
Article / Updated 01-31-2018
The main reason to work with structures in most code is to create records that contain custom data. You use these custom data records to hold complex information and pass it around as needed within your application. It’s easier and faster to pass a single record than it is to pass a collection of data values, especially when your application performs the task regularly.
Article / Updated 01-31-2018
Expression-bodied members first appeared in C# 6.0 as a means to make methods and properties easier to define. In C# 7.0, expression-bodied members also work with constructors, destructors, property accessors, and event accessors. Creating expression-bodied methods The following example shows how you might have created a method before C# 6.
Article / Updated 01-31-2018
In Visual Studio, and in C#, Visual Basic .NET, and the other .NET languages, one project equals one compiled module — otherwise known as an assembly in .NET. The words module and assembly have somewhat different technical meanings, but only to advanced programmers. Executable or library? Executable (.EXE): A program in its own right that contains a Main() method.
Article / Updated 01-31-2018
You may decide that you don’t want future generations of programmers to be able to extend a particular class. You can lock the class by using the keyword sealed. A sealed class cannot be used as the base class for any other class. Consider this code snippet: using System;public class BankAccount { // Withdrawal -- You can withdraw any amount up to the // balance; return the amount withdrawn virtual public void Withdraw(decimal withdrawal) { Console.
Article / Updated 01-31-2018
After you have the gist of using delegates, take a quick look at Microsoft’s first cut at simplifying delegates in C# 2.0 a couple of years ago. To cut out some of the delegate rigamarole, you can use an anonymous method. Anonymous methods are just written in more traditional notation. Although the syntax and a few details are different, the effect is essentially the same whether you use a raw delegate, an anonymous method, or a lambda expression.
Article / Updated 01-31-2018
C# keeps track of whether a variable has been initialized and doesn’t allow you to use an uninitialized variable. For example, the following code chunk generates a compile-time error:public static void Main(string[] args){int n;double d;double calculatedValue = n + d;}C# tracks the fact that the local variables n and d haven’t been assigned a value and doesn’t allow them to be used in the expression.
Article / Updated 01-30-2018
You can generate static in C# class members. Most data members of a class are specific to their containing object, not to any other objects. Consider the Car class:public class Car{public string licensePlate; // The license plate ID}Because the license plate ID is an object property, it describes each object of class Car uniquely.
Article / Updated 01-30-2018
In versions of C# prior to C# 7.0, every return value was a single object. It could be a really complex object, but it was still a single object. In C# 7.0, you can actually return multiple values using tuples. A tuple is a kind of dynamic array nominally containing two items that you can interpret as a key and value pair (but it isn’t strictly required).