Category Archives: syntax

Use the automatic code converters at developerFusion to convert C# code into Visual Basic, Ruby, and Python

The developerFusion web site provides code converters that let you translate between C#, Visual Basic, Ruby, and Python. One of the most important uses for reflection is analyzing code to figure out what it does. Once you know what the … Continue reading

Posted in programs, reflection, syntax | Tagged , , , , , , , , , , , , , , , | 1 Comment

Implement interfaces explicitly or implicitly in C#

Suppose you create a class and in the declaration you indicate that it implements one or more interfaces. If you right-click an interface’s name, the dropdown displayed by Visual Studio includes an “Implement Interface” submenu. If you look at the … Continue reading

Posted in interfaces, syntax | Tagged , , , , , , , , , , | Leave a comment

Understand ways to end case blocks in C#

There are several ways that you can exit case blocks in a switch statement. For example, consider the following code. string result = “”; int control = 1; switch (control) { case 1: case 2: result = “One or two”; … Continue reading

Posted in syntax | Tagged , , , , , , , , , , | 2 Comments

Understand region directives in C#

Region directives let you define sections of code that you can collapse and expand by clicking the – and + signs to the left in the code window. Each region directive should have a corresponding endregion directive. You can include … Continue reading

Posted in coding, syntax | Tagged , , , , , , , , , , | 3 Comments

Disable Visual Studio warnings in C#

Visual Studio warnings let you know when your code contains something suspicious. For example, suppose you have XML documentation enabled. To enable XML documentation, open the Project menu and select Properties. On the Build tab, check the XML Documentation File … Continue reading

Posted in coding, syntax | Tagged , , , , , , , , , , , | Leave a comment

Extract comments from a group of files in C#

I’m finishing up another book (I’ll announce it when it’s ready in a week or so) and I’m working through one of the thornier issues of any programming book: spell-checking code comments. I already have an example to extract comments … Continue reading

Posted in files, strings, syntax | Tagged , , , , , , , , , , , , | Leave a comment

Cast arrays from one reference type to another in C#

Every C# programmer knows that you can use a cast operator to convert one data type into another. For example, if the Employee class inherits from the Person class, then the following code creates an Employee object and then makes … Continue reading

Posted in arrays, syntax, variables | Tagged , , , , , , , , , , , , , | Leave a comment

Validate optional parameters in C#

The example Use named and optional parameters in C# explains how to use named and optional parameters to let the calling code omit any combination of parameters. In many applications, you may not want to allow the user to omit … Continue reading

Posted in methods, syntax, variables | Tagged , , , , , , , , , , , , , | 1 Comment

Use named and optional parameters in C#

Optional parameters is one of the few additions in recent versions of Visual Studio that are really useful. I usually try to post examples in an older version of C# because it’s easier for someone to move an older example … Continue reading

Posted in methods, syntax, variables | Tagged , , , , , , , , , , , , , | 1 Comment

Iterate over items in an array with unknown dimensions in C#

This example shows how you can iterate over the items in an array that has an unknown number of dimensions. When it starts, the program executes the following code. private void Form1_Load(object sender, EventArgs e) { string[, ,] values = … Continue reading

Posted in algorithms, arrays, syntax | Tagged , , , , , , , , , , , , , | 2 Comments