
Even though I am a Technical Writer, from time to time I must learn new programming languages so that I can stay at the cutting edge of my profession. Currently, I work with a group of professionals that utilize Microsoft Visual C#. According to Microsoft Press, books about Visual C# were the leading sellers among programming books in 2006 and 2007. Also, if you investigate applications being built for both local desktops as well as the web, many of them have been built using Microsoft Visual C#. At some future point I also want to learn PHP, but right now, I believe there is a lot I can contribute to my professional experience by learning this emerging and dynamic object-oriented programming language developed by Microsoft. So, I hope you similarly benefit from these postings.
Today’s lesson is going to feature the very essentials of a Visual C# application: (1) Whitespace, (2) Visual C# keywords, (3) Literals, and (4) Identifiers.
Whitespace: Because C# compilers ignore whitespace, you should make liberal use of it to help format your code and make it readable to other programmers and managers besides yourself. Whitespace is the blank space put into a listing. Whitespace can consist of spaces, tabs, line feeds, and carriage returns.
Example: int radius = 10;
The same expression could be written as: int radius = 10 ;
The second line compiles exactly the same as the first line. So, Visual C# is able to intelligently interpret the white space and not see it as meaning anything extra. The only exception to this rule is that when you use double quotations, this is a fixed text string, so the compiler will not change this in any way. They way you enter the text is the way it appears in the compiled output.
Keywords: There are approximately seventy-six (76) keywords in the Microsoft Visual C# language. Keywords cannot be used outside their designated and functional purposes. The following list is a list of these seventy-six keywords with a brief definition:
abstract: a modifier that can be used to indicate that a class is to be used only as a base class to another class.
as: an operator used to perform conversations between compatible types. The value to the left of the operator is cast as the type on the right.
base: a keyword that enables values and types in a base class to be accessed.
bool: a logical data type that can be either true or false. Bool is equivalent to System.Boolean in the Microsoft .NET framework.
break: a program flow keyboard that enables programs control to exit a loop or a conditional block, such as “switch” or “if”.
byte: a data type that stores an unsigned integer in 1 byte. This is a value from 0 to 255. This keyword is equivalent to System.Byte in the Microsoft .NET framework.
case: a program flow keyword that defines a logical condition within a switch statement.
catch: part of the try-catch error-handling logic of a program. The catch blocks are used to specify exceptions to be handled and the code to be executed when such exceptions occur.
char: a data type that stores a single Unicode character in 2 bytes. This keyword is equivalent to System.Char in the Microsoft .NET framework.
checked: a program flow keyword that indicates that overflow-checking for integer-type arithmetic operations and conversions should occur.
class: a reference data type that can contain both data and method definitions. A class can contain constructors, constants, fields, methods, properties, indexers, operators, and nested types.
const: this is a modifier that is applied to a data member or variable. When used, the value of the data type is constant and, therefore, cannot be changed.
continue: this is a program flow keyword that enables program control to automatically go to the next iteration of a loop.
decimal: this is a data type that stores a floating-point number in 16 bytes. The precision of a decimal variable is better than that of the other floating point types. This makes it better for storing financial values. The suffixes m and M designate a decimal literal. This keyword is equivalent to System.Decimal in the Microsoft .NET framework.
default: this keyword is a label within a switch statement to which program flow goes when there is no matching case statement.
delegate: this keyword is a reference type that can receive a method based on a specified method signature. This signature of methods is based on the declaration of the delegate (similar to function pointers in languages such as C and C++).
do: this is a looping program flow construct that causes execution of a statement or block of statements until a condition at the end of the block evaluates to false.
double: this is a data type that stores a floating-point number in 8 bytes. The suffixes d and D designate a double literal. This keyword is equivalent to System.Double in the Microsoft .NET framework.
else: this is a conditional program flow statement that contains a statement or block of statements that is executed when a preceding if statement evaluates to false.
enum: this is a value data type that can store a number of predetermined constant values.
event: this is a keyword used to specify an event. The event keyword enables a delegate to be specified that can be called when an “event” occurs in a program.
explicit: this is a keyword used to declare an explicit conversion operator for a user-defined type.
extern: this is a modifier that indicates that a method is external and, thus, outside the C# code.
false: this is a boolean literal value. This keyword can also be used as an operator that can be overloaded.
finally: the finally block executes after the try block’s scope ends. It is generally used to clean up any resources allocated in the try block.
fixed: a keyword used within unmanaged code to lock a reference type in memory so that the garbage collector won’t move it.
float: this is a data type that stores a floating-point number in 4 bytes. The suffixes f and F designate a float literal. This keyword is equivalent to System.Single in the Microsoft .NET framework.
for: a program flow statement used for looping. This statement contains an initializer, a conditional, and an iterator. The statements within the for construct’s block execute until the conditional evaluates to false. The initializer is executed at the start of the for. The iterator is executed after each execution of the for statement’s statement block.
foreach: an iterative program flow construct that enables you to loop through a collection or array.
get: a special word used for creating an accessor that gets the value from a property. This is not a reserved word.
goto: this is a program flow constant that jumps program flow from the current location to a labeled location elsewhere in the program.
if: this is a program flow construct that executes a block of code when a condition evaluates to true.
implicit: this is a keyword used to declare a user-friendly defined type conversion operator that does not have to be specified (e.g. called implicitly).
in: this is a keyword used with the foreach keyword. This keyword identifies the collection or array that the foreach will loop through.
int: a data type that stores a signed integer in 4 bytes. The range of possible values is from -2,147,483,648 to 2,147,483,647. This keyword is equivalent to System.Int32 in the Microsoft .NET framework. Literal numbers with no suffix are of type int by default if the value fits within the given range for an int.
interface: this is a keyword used to declare a reference type that defines a set of members but does not declare them.
internal: this is an access modifier that enables a data type to be accessible only from within files in the same assembly.
is: this is an operator used to determine at runtime whether an object is a specified type.
lock: this is a keyword used to make a block of code critical. This section of code does not enable more than one thread to access it at a time.
long: this is a data type that stores a signed integer in 8 bytes. The range of possible values is from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. This keyword is equivalent to System.Int64 in the Microsoft .NET framework. The suffixes l and L designate a long literal.
namespace: this is a keyword that enables you to organize a number of types into a group. This is used to help preven name collisions and to make it easier to reference types.
new: this is an operator used to create an object. This is also used as a modifier to hide a member inherited from a base class.
null: this is a literal used to represent reference value points to nothing.
object: this is a type based on the System.Object. class in the .NET framework. All other types are derived from object.
operator: this is a keyword used to create or overload an operator’s functionality in a class or structure.
out: this is a parameter modifier that enables the parameter reference variable to be used to return a value from a method. The variable must be assigned a value in the method.
override: this is a keyword used to provide a new implementation of a method or property, which replaces a base class’s existing method or property with the same signature.
params: a parameter modifier that indicates that a variable number of values can be contained in the parameter. This modifier can be used only with the final parameter in a method’s parameter list.
partial: a potential future keyword used to indicate that the associated class is only partially defined in the current listing. This allows a single class to be broken across multiple source listings.
private: this is an access modifier that indicates that a method, property, or other member of a structure or class is accessible only within the same class or structure.
protected: this is an access modifier that indicates that a method, property, or other member of a class is accessible only within the same class or within classes that are derived from this class.
public: this is an access modifier that indicates that a method, property, or other member of a class or structure is accessible.
readonly: this is a data member modifier that indicates that after the initial assignment - either at the time of declaration or within the constructor - the value within the data member cannot be changed.
ref: this is a parameter modifier that indicates that changes to the parameter variable will also be reflected in the variable that was passed as the ref argument.
return: this is a keyword used to return a value from a method.
sbyte: this is a data type that stores a signed integer in 1 byte.
sealed: this is a modifier for classes that prevents you from deriving from the class.
set: this is a special word used for creating an accessor that sets the value in a property.
short: this is a data type that stores a signed integer in 2 bytes.
stackalloc: this is a keyword that is used to allocate a block of memory on the stack.
static: this is a modifier that is used to indicate that only a single value will be stored for the type.
string: this is a data type that stores Unicode characters. String is an alias for System.String in the Microsoft .NET framework.
struct: this is a value data type that can contain both data and method definitions. A structure can contain constructors, constants, fields, methods, properties, indexers, operators, and nested types.
switch: this is a program flow construct that changes program flow based on a value of a variable.
this: a keyword used within a non-static method that associates a variable with the current instance of a class or structure.
throw: a program flow statement that is used to throw an exception, which indicates that something abnormal has occurred. This is used with try and catch.
true: this is a boolean literal value. True can also be used as an operator.
try: this keyword is used for exception handling.
typeof: this is an operator that returns the data type of an object.
uint: this is a data type that stores an unsigned integer in 4 bytes.
ulong: this is a data type that stores an unsigned integer in 8 bytes.
unchecked: this is an operator or statement that can be used to indicate that overflow checking on integer data types should be ignored.
unsafe: a keyword used to identify code that is considered unsafe to execute in the managed environment. For example, unsafe should be used to wrap any code that uses pointers.
ushort: this is a data type that stores an unsigned integer in 2 bytes.
using: this is a keyword for creating an alias for a namespace. It can also be used to shortcut the need to use fully qualified names for types within a namespace.
value: the name of the variable being set by a set property accessor.
virtual: a modifier used on a method or property to indicate that the method or property can be overridden.
void: this is a keyword used in place of a type to indicate that no data type is used. In method declarations, void can be used to declare that no value is returned from the method.
where: this is a potential future keyword used to declare constraints on generics.
while: this is a looping program flow construct that causes execution of a statement or block of statements as long as a condition evaluates to true.
yield: this is a potential future keyword that is used within iterators to indicate a value that should be returned to a foreach statement. The yield keyword indicates where the foreach statement should continue on its next iteration.
Literals: these are straightforward hard-coded values. They “are what they are”. Simple as that.
Identifiers: is the name given to the class, and class-body is the code that makes up the class.
Here is a brief example:
class identifier
{
class-body;
}
Questions? Just shoot me an e-mail at great.documents@gmail.com.
I’ll try my very best to answer your question
All The Best, Keith
(Inspired Source: Teach Yourself C# in 21 Days, by Bradley Jones)
Written by Keith Johnson
July 13th, 2008
Add Comment »