Solo disponible en BuenasTareas
  • Páginas : 8 (1859 palabras )
  • Descarga(s) : 0
  • Publicado : 21 de agosto de 2012
Leer documento completo
Vista previa del texto
C# for Delphi Developers
By Glenn Stephens Introduction C# has really gathered momentum in the last few years. As a powerful OO language it combines the best features of many programming languages. As the C# language was designed by Anders Hejlsberg, who was one of the original architects on C#, Delphi style themes can be seen inthroughout C# language and the .NET framework. This means many Delphi developers will find themselves comfortable with C# and the .NET framework after they learn the differences between the two languages. This paper/session will teach the Delphi VCL developer what it takes to start to move to C# and .NET. This paper will not go into depth with the each class in the .NET Framework, but instead will coversome of the C# ways that you are used to doing in Delphi. Also this paper doesn’t show every equivalent of Delphi’s language, but it is intended to take you as far as you need to go in order to start building apps with C#. So why should I bother with C#? Good question. Not everyone will want to learn C#, but there are a few trends that are emerging. One reason is that many of the samples in .NETdeveloper articles and journals are using C#, so you will need to understand C# a little to understand the techniques that are being used. Another reason is that many of the component vendors are only writing their .NET components in C#, so if you want to extend the functionality of your components when you buy source you may need to get your hands dirty and code some C#. There are plenty ofreasons to use C# from understanding samples to just playing with it because it’s new. Either way it’s a good language that you will find useful. Language differences/similarities

You may say ‘C# is just Java’. It’s kind of a true-ism. It sounds true but it’s not really. I have programmed Java for a while and when I first got my hands on C#, I just wrote simple Java code and it seemed to work. Inreality though, there are many differences. C# and Java are kind of like the siblings that don’t get along. Yeah the might look the same, but they have their own individualities. So those of you who know Java, you will probably find working with C# pretty easy. But if you’re reading this paper, chances are you’re a Delphi Developer. So if you know a little C, C++ or Java you will find this prettyeasy. For Delphi developers, the language is different. You will need to know the ways to transpose the code from Delphi-ism into C#-isms. Once you are familiar with the ‘isms’, you should be able to do pretty much what you like. Much of this paper will show you the Delphi way of doing things and then show you the C# way (see Listing x), and will discuss any gotcha’s along the way. One of the maindifferences that you will find with C# is that the language is case sensitive. This means MyVar, myvar, MYVAR and myVAR are all different variables. One of the things I have always liked about Delphi is that you don’t have to remember the case. With C# you tend to rely on the code completion features a little more so you don’t stuff up the variable names. A Typical C# File Just like Delphi has itsown semantics on how you set up a file, C# has its own way. Let’s look at a simple C# file.
using System; namespace Project4 { public enum FavouriteMovie { PrincessBride = 1, DudeWheresMyCar = 2, HarryPotter2 } public class MyDemoClass { protected int SomeValue = 12; public MyDemoClass() { } public void SomeMethod() {

//Do something } public int AddSomeNumbers(int a, int b) { return a + b; }} }

Basically you have the assemblies that you will be using at the top. This is like the uses clause in Delphi. You will then have the namespace declaration, which defines what namespace you code belongs to. Within the namespace you then have your information that this source file might contain such as type declarations (see the FavouriteMovie enumeration) or class declarations such as the...
tracking img