![]() |
|
#1
|
||||
|
||||
Introduction to .NET Introduction
In my experience I found that people starting to learn a new programming language find it hard to accomplish this by reading “complicated and sophisticated” books written by the experts that developed or helped maintain the respective language. They find easier to understand explanations given by everyday people (like myself), and after finding out in a few, clumsy words what the respective language is about, they can adventure themselves in the wonderful experience of learning from the people who really know what they are talking about! NOTE: This is only intended as a brief introduction to the world of .NET. More to come, hopefully… The .NET Framework
The .NET Framework is a platform for building powerful Web Services and applications. It consists of 3 main parts:
Programming languages “Managed code” producing languages C# Visual Basic .NET JScript .NETHybrid (can produce managed and unmanaged code) Visual C++.NET SDK download Just go to http://www.microsoft.com/net. You will be able to get csc (C-sharp Compiler) for free, but this is only a command-line application – you need to buy VS.NET for the working environment (you could do without it). Some basic concepts and terminology CLR - Common Language Runtime It is, basically, the execution engine for .NET Framework applications. CTS– Common Type System It is, obviously, the .NET Type System. Common means that it supports the types and operations found in most programming languages CLS – Common Language Specification Being a subset of the CTS, it also is what makes .NET so beautiful! It consists a truly guide for programmers developing libraries and compilers. If they stick to this model, the result is that their designed - libraries: are guaranteed to be perfectly usable from languages supporting the CLS - compilers: allow the respective languages to integrate with each other MSIL – Microsoft Intermediate Language MSIL is the instruction-set into which .NET programs are compiled. It is CPU-independent, just like Java .class files (I will get back on this “striking resemblance” in concept with Sun’s Java) MSIL, together with the CTS, allows cross-language integration (this really is a new MS-made feature). In order to execute, the MSIL is first converted to machine code. As opposed to Java, there is NO run-time interpretation involved => a plus in execution speed. “ Managed code ” I bet you heard this a thousand times. In case you wondered what it meant and didn’t bother to find out just then, here is my dumb description: Managed code is code written for the CLR, providing special metadata to the runtime. The only .NET programming language that doesn’t produce managed code by default is C++. However, it to can be “persuaded” to do this by using the /CLR switch on the command-line compiler. Managed data is the data allocated/de-allocated by the runtime’s Garbage Collector (more about gc in a bit). VC++.NET can have access to the benefits of managed data through ME (Managed Extensions). For instance, in order to have a C++ class derive from a C# one, you need to make it a managed class, as the .NET Framework requires. You can do that by applying the _gc modifier to the class. This signals the compiler the class falls under the rules of Garbage Collection, and every instance of the class will be managed by the gc . Of course, as a fall back, you won’t be able to use multiple inheritance with your C++ class, as this is forbidden by the .NET Framework. (you can, however, use interface implementation – unfortunately, this doesn’t make the object of my very brief and basic introduction) The Garbage Collector Finally! This concept is familiar to Java programmers, but new to C++ developers. The garbage collector is responsible for de-allocating memory used by objects when they are no longer accessible (they go out of scope). The developer who wrote the class the object belongs to can write a special clean-up routine called a finalizer. This routine will always execute, no matter when the memory is freed, and should contain code written by the programmer to de-allocate special system resources, like file handles, for instance. The Garbage Collector will release the other resources when compacting the work set. C#
What is C#? Tough question! Pathetic definition: C# is an Object Oriented programming language, designed by Microsoft, with a clear affiliation to the C/C++ family of languages, but with a higher, more evolved conceptual design. In other words, it is kind of “Microsoft’s Java”. Actually, in their previous version of Visual Studio, they had a Java editor called Visual J++, which they stopped developing once C# came in (there I, of course, J# - very strange to me, as it doesn’t have recognition from Sun and remains only a MS “private” developing environment). Therefore, the nickname is well deserved. Although Microsoft has tried to illustrate C# as a combination of C++ and Visual Basic, I really don’t see very much of VB in it. Of course, I’m no VB programmer, so I might be wrong… C# uses the .NET class library (as do all .NET languages). Unlike C++, it is built to work within the .NET Framework. I think ME (Managed Extensions) for Visual C++ were added as a feature and VC was kept in the .NET version of VS.NET because they needed an environment capable of porting *old style* applications to the .NET Framework. I feel that C# (or VB) should be used for everything else. A very simple C# application You can build your very first C# application with a simple text editor – let’s say, Notepad! This will only be a console application, but hey, it’s a start… C-SHARP / C# Code:
Observe how I “cleverly” avoided using the boring “Hello world” example ? You will run this example from the comand prompt like this: Code:
This if you have the Environment Variables set….(if you don't, than do it, or just go to the right directory; I won't show here how to do it; I just won't! ) Superficial code walk-through You’ll notice that, just like in Java, the Main method needs to be encapsulated inside a class (also, you can’t use main). Instead of calling System.Console.WriteLine, we could have done this: C-SHARP / C# Code:
Therefore, System is a namespace we can use to shorten our code! (hilarious explanation, right?) So, what about this WriteLine? Pascal writeln? C printf? Who knows – this is just what we are stuck with for console output… We can use as many parameters as we want, by simply incrementing the value inside the brackets ({0},{1},{2} etc.) Also notice we don’t need to use both args and argv in order to accept parameters, as we would in C++, just a string will suffice. Some new C# concepts
Introducing Properties C++ programmers are familiar with this technique, they just don't know what it is! Actually, there are some changes in approach, but the concept is the same. When declaring private member data to your classes, you should supply methods to acces this data, like so: C-SHARP / C# Code:
In C#, there is a built-in mechanism implementing this technique, in order to make our work easier and to produce more transparent code: C-SHARP / C# Code:
I think the similarity is pretty obvious. The get and set are called getter and setter methods. Notice the value in the setter method? This is also part of the built-in mechanism. It will take the value passed to the setter. Also, notice that we don't have to fill in ; after the definition of the class. However, we can do that, without the compiler bothering us. This feature is to keep both Java and C++ programmers comfortable. In C#, just like in Java, you need to supply the modifiers for each field. I think this is intended to keep us from making mistakes (yeah, right, like this little thing could stop us Usually, the property name will be the name of the field, only with a Capitalized first letter. Please stick to this naming scheme, or you will miss out on the whole properties purpose. Finally, what are they good at? Well, here is how you'd use them: C-SHARP / C# Code:
So, could you tell (just by thinking in C) that ProtosName and ShieldEnergy are not public member data? Properties will make it easier for programmers working on the same project to continue your work, as by the completely new naming scheme it is easier to find accessors for your data and use it. Of course, this means it is easier for you to get laid off, since anybody can understand your code, and you aren't the only "genius" able to continue your work Just for fun More about Properties here Attributes If you'll read some C# samples, you are bound to come across something like this: C-SHARP / C# Code:
So. What is that [STAThread]? That, my forum-reading friends, is a C# attribute. I think that attribute defining can be pretty tricky sometimes, since it involves rather advanced concepts, likeReflection, so I won't go into all that. I just want to mention this is a really important C# concept, and I would strongly suggest you do some serious reading on this. You could start here. By the way, the [STAThread] attribute is used to define the COM threading model (Single Threaded Apartments). It is pretty obvious the other option would be [MTAThread]. I'll just show you a sample of a .NET environment defined Attribute, Obsolete (as it is pretty easy to use): C-SHARP / C# Code:
Indexers This feature enables programmers to treat class instances(objects) as they would arrays. Actually, indexers are sometimes called "virtual arrays", since they enable classes to emulate their behavior. Indexers are closely related to properties. Thus, in order to create an indexer for a class, you create a property with the name this (all C++ programmers can easily figure out why, so I won't insist on this), but also supply it with a set of [], and an "array index" between them. Here's a short sample: C-SHARP / C# Code:
You will use your brand new indexer like this: C-SHARP / C# Code:
Got the picture? Hope so… You can read much more here This is it for now. This should help people completely new to the .NET architecture get an idea about what they are dealing with. If you read this small, clumsy introduction, please don't stop here! There are so many things to learn in this wonderful, brand new world! (personal opinion) NOTE: I didn’t cover important concepts like Assemblies and Modules here, because I didn’t feel it was the right place (since my introduction was at a very basic level). I promise to get back on this (and lots more) in the upcoming future. __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein Last edited by LuciWiz : 16-Apr-2005 at 06:37.
|
|
#2
|
||||
|
||||
|
Quote:
This is, of course, a stupid thing to say. I meant build. Just like in Java, there are 2 stages in running a program. 1. Code:
=> Application.class 2. Code:
Code:
The difference with C# is that it generates an .exe. 1. Code:
2. Code:
Now this is running! (terrible sorry about the missusage of words) Also, I've noticed that my code formatting went crazy when pasting from Word - I would change it, but it seems that the same rules apply to this forum as to the others, and I can't anymore. Why didn't I do it right away? Good question...that's me, I guess Regards, Luci __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#4
|
||||
|
||||
Re: Introduction to .NETClasses and Structs
Classes and Structs look exactly the same in C#, when they are declared and used. The difference is that one is using stack and the other heap memory.
classes can be extended (allow for inheritence), structs cannot structs are fixed size, and so can be allocated on the stack, and allocated in arrays directly. C-SHARP / C# Code:
__________________
Xrum! |
|
#5
|
|||
|
|||
Re: Introduction to .NETI like the tutorial, just a suggestion, you should split the .NEt in more categories (VB,C#,ASP) so ppl cand find what they are looking exactly.
|
|
#6
|
|||
|
|||
Re: Introduction to .NETI was so stupid posting a thread asking what a .net is...
|
Recent GIDBlog
A Week in Kuwait by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| VC++ .NET Windows and interrupts / watchdogs question. | bmwrob | MS Visual C++ / MFC Forum | 0 | 30-Jun-2004 21:06 |
| UDP Sockets between .NET and VS6 | MikeZ | MS Visual C++ / MFC Forum | 2 | 19-Feb-2004 10:55 |
| .NET Mobile Controls Device Update 3.0 Available at DiscountASP.NET | dasp | Web Hosting Advertisements & Offers | 0 | 15-Sep-2003 16:26 |
| IP*Works! CC ICharge .NET Edition Launched at DiscountASP.NET | dasp | Web Hosting Advertisements & Offers | 0 | 25-Aug-2003 19:27 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The