Visual C#.NET : Code Safer
Introduction
Programmers familiar with C/C++ or Java may feel a sense of deja vu when first coming
into contact with the C# (pronounced C Sharp
) language, which, considering
C# has its roots in the C++ language, should not be surprising. C# is developed
by Microsoft to implement its .NET framework.
Avantages?
C# is a highly-managed language. What this means that the compiler
will not
allow unsafe operations, unless explicitly forced to do so. This is intended to
prevent the unintentional errors in logic and syntax other languages allow inexperienced
programmers to code.
One of the unsafe operations
C# forbids is implicit conversion between incompatible
datatypes. For instance, you cannot implicitlly convert a Double object into a
Single or Integer object. Why? Because your data becomes truncated. Single
and Integer types are narrower
, meaning they have a smaller memory value, than Double
types. This could theoretically cause improper execution of code that tests the equivalency
of two or more objects.
Cool! Hey, why did you quote compiler
? Something I should know?
That's for one simple reason. C#, like most modern OOP languages, does not actually
compile. Rather, it is interepted
into MSLI byte-code when you ask your development
environment to build the project code. Then, at runtime, a JIT (Just-In-Time)
compiler completes the compilation into machine code. The advantage of using a JIT
compiler versus a true
compiler is that the executable can be easily ported
from system to system, as long as the proper runtime environment is present. For
Microsoft languages, the necessary runtime is the .NET Framework.
While this does make our code more portable (anything that can run a newer version of Windows can probably run our code), it also means our application takes longer to execute. Of course, the average user will never notice, as this only becomes an issue with systems that require high-speed processing, such as precision mold software or industrial color spectrum analyzers...
C# Keywords
There are certain words that have special meaning the C# compiler and cannot be used in your code for anything else unless you precede them with the @ sign.
The following list is every keyword as of .NET Framework 3.5.
abstract
event
new
struct
as
explicit
null
switch
base
extern
object
this
bool
false
operator
throw
break
finally
out
true
byte
fixed
override
try
case
float
params
typeof
catch
for
private
uint
char
foreach
protected
ulong
checked
goto
public
unchecked
class
if
readonly
unsafe
const
implicit
ref
ushort
continue
in
return
using
decimal
int
sbyte
virtual
default
interface
sealed
volatile
delegate
internal
short
void
do
is
sizeof
while
double
lock
stackalloc
else
long
static
enum
namespace
string
Source: MSDN Visual C# Developer Center
Home
About
Blog
Credits
RSS
Comments ( 0 ) •
Sorry. There are currently no comments for this article.