Archive for May, 2009

Working with Multiple Forms using Visual C# 2008

You will need to work with more than one form while developing Windows based applications in C#. In this code snippet, Anand examines the steps required using Visual C# 2008.

Read more...



1 comment - What do you think?
Posted by Anand Narayanaswamy - May 25, 2009 at 7:40 am

Categories: Latest, Programming   Tags: , , , , , , , , , , , , , , , , , ,

What are Identifiers and Keywords?


Identifiers are the names given to classes, methods, variables and interfaces. It must be a whole word and starts with either an alphabet or an underscore. They are case sensitive. The main point you should bear in mind is that the names should not clash with C# keywords. Some programmers use @ prefix as a first character while declaring identifiers to avoid clash with a keyword but it is not a recommended practice. Following names are valid identifiers in C#

1. Hello
2. hello
3. H_ello
4. HelloWorld

You should name the variables using the standard DataType prefixes. Also the first alphabet after the prefix should be capitalized. Table 1 shows a list of prefixes for the various .NET DataTypes. Interfaces should be named with "I" as the first alphabet so that you can easily distinguish it from a class.

Table 1

Data Type

Prefix

Example

Array

arr

arrNumber

Boolean

bln

blnSelect

Byte

byt

bytNumber

Char

chr

chrPick

DateTime

dtm

dtmPick

Decimal

dec

decPoint

Double

dbl

dblData

Integer

int

intVar

Long

lng

lngMiles

Object

obj

objVar

Short

shr

shrNumber

Single

sng

sngNumber

String

str

strAddress

All Windows Forms controls should be named with the special prefixes as shown in Table 2. This is to avoid confusion and also to distinguish between other controls in a complex project. As explained above, the first alphabet after the prefix should be capitalized. Once you master the naming conventions and prefixes it would be very easy for you to write and maintain code.

Table 2

Control Name

Prefix

Example

Button

btn

btnSubmit

TextBox

txt

txtFname

CheckBox

chk

chkHobbies

RadioButton

rad

radMale

Image

img

imgIndia

Label

lbl

lblCity

Calendar

cal

calDate

It is beyond the scope of this chapter to cover the prefixes of all the .NET controls. You will find a detailed list of them on the MSDN Library. Keywords are special words built into the C# language and are reserved for specific use. This means you cannot use them for naming your classes, methods and variables. For instance, if you attempt to use a C# keyword (if) as your class name, the C# compiler will emit runtime error as shown in Figure 1.

What are Identifiers and Keywords?

In order to resolve the problem, you may have to change the class name to some other meaningful name. There are around 80 keywords in C#, which can be used by programmers to develop applications using the user friendly language.

Be the first to comment - What do you think?
Posted by Anand Narayanaswamy - May 23, 2009 at 1:41 am

Categories: C#, Channels, Latest   Tags: , , , ,

What are the requirements for developing a C# application?

The first major requirement is that you should require a system running either Windows 2000 Professional or Windows XP Professional or Windows 2003/2008 Server. Windows XP Home Edition doesn’t provide support for .NET. It is not recommended to work with C# on Windows 98 systems as it is not compatible for developing server side applications or ASP.NET. Microsoft Vista Ultimate completely supports .NET Framework. The recently released release candidate of Windows 7 also provide support for .NET Framework. Linux also supports C# with the help of Mono C# compiler Kit.

Secondly, you should install .NET Framework Software Development Kit (SDK) which can be downloaded from the website of Microsoft located at http://msdn.microsoft.com/downloads. Windows 2003/2008 Server ships with .NET Framework and hence there is no need to install the SDK separately. However, it doesn’t comes with Visual Studio.

Finally, you require an editor to enter codes. In programming parlance, codes are called as source codes. They are nothing but syntaxes which adheres to the C# language conventions. Notepad is one of the most popular editors among many programmers. Even though Notepad is sufficient to learn C#, it would be better if you have installed Visual Studio. It ships with Visual C#, which offers many advanced functionalities than a traditional editor like Notepad.

Many third party vendors have released editors for programming with C# and other .NET languages. Notable among them are SharpDevelop and Antechinus C# Editor using which you can not only create HTML, XML, XSL and ASCX files but also the files oriented for ASP.NET development.

Be the first to comment - What do you think?
Posted by Anand Narayanaswamy - May 18, 2009 at 12:47 am

Categories: C#, Channels, Latest   Tags: , , , , , , , , , , , , ,

What are Namespaces?

As I explained in a previous FAQ, namespaces are placed at the top of the .NET hierarchy. Namespaces are nothing but group of classes or types or assemblies. Each of these classes contains lot of methods. Basically, namespaces are treated as containers for all classes and are classified into several categories, based on its functionalities. For example, if you need to work with databases, you have to call the namespace System.Data. Similarly, if you are working with files you have to call System.IO namespace.

Namespaces in C# are similar to packages in Java, where we will use a statement like java.sql.* Moreover, all C# programs should call System namespace. This is the root of all other namespaces in the .NET Framework.

Be the first to comment - What do you think?
Posted by Anand Narayanaswamy - May 15, 2009 at 1:14 am

Categories: C#, Channels, Latest   Tags: , , , , , , , , , , ,

What do you mean by .NET Framework Class Libraries?

The .NET framework class libraries are the core part of any .NET Framework programming language. It contains around 3400 classes classified logically into namespaces. Each class contains numerous methods and properties which you will use for your programming tasks. These libraries are available for any language under the Common Language Runtime environment.

Be the first to comment - What do you think?
Posted by Anand Narayanaswamy - May 14, 2009 at 12:57 am

Categories: C#, Channels, Latest   Tags: , , , , , , , , , , ,

FAQ 4 – What is Common Language Runtime?

Common Language Runtime shortly called as CLR provides a universal execution engine for .NET applications and it is provided by the .NET Framework. Every target computer should require CLR for executing .NET applications. One of the most interesting points to note is that the CLR itself manages the life of objects. This is the effect of Automatic Garbage Collection system built into it. When the CLR finds an object that is not being used, it destroys them and thus freeing memory allocation.

The corresponding compilers (C#, Visual Basic .NET) generate meta code upon successful compilation. This meta code contains lot of information about code types, its members and references used. The CLR generates Simple Object Access Protocol (SOAP) when it makes remote procedure calls. SOAP is a protocol used to access .NET Web Services. In addition to the garbage collection, CLR also provides support for Managed Code, Effective Memory Management, Type Safety Verification, Conversion of IL to native code, Structured Exception Handling and Effective Interoperability between COM components and Unmanaged Code. You can build secured applications using the runtime since the .NET Framework provides support for advanced security features as well.

Be the first to comment - What do you think?
Posted by Anand Narayanaswamy - May 13, 2009 at 12:41 am

Categories: C#, Channels, Latest   Tags: , , , , , , , , , , , , , , , ,

FAQ 3 – What is C#?

C#, pronounced as C-Sharp, is one of the powerful programming languages provided by the .NET Framework. According to Microsoft “C# is a modern, object-oriented language that enables programmers to quickly build a wide range of applications for the new Microsoft .NET platform, which provides tools and services that fully exploit both computing and communications”. The main brains behind C# were Anders Hejlsberg and Scott Wiltamuth. However, many other personalities like Rob Howard, Scott Guthrie were also involved behind C# and the .NET Framework. The programming language has been standardized by European Computer Manufactures Association (ECMA).

Microsoft originally released beta versions of .NET Framework to get feedback about the product from developers and customers. Based on the massive response and suggestions received from them for the first beta, Microsoft released second beta in early 2001. Finally, they released final versions of C# under the name, .NET Framework 1.0 in 2002 and that of 1.1 in 2003. With each release, the product shipped with improved features for developing secured and scalable applications along with high quality documentation.

Be the first to comment - What do you think?
Posted by Anand Narayanaswamy - May 13, 2009 at 12:37 am

Categories: C#, Channels, Latest   Tags: , , , , , , , , , , , , , , ,

FAQ 2 – What is Microsoft .NET?

Microsoft .NET is one of the latest and powerful technologies introduced by Microsoft Corporation. It is comprised of several programming languages and each of these languages works under a common framework called .NET Framework. Developers had faced lot of difficulties while working with earlier languages. These difficulties were completely eliminated with the introduction of .NET. Microsoft .NET platform comprises of core components like .NET building block services such as Passport .NET, .NET device software’s that will run on latest Internet devices like mobile phones, handhelds and pocket PC’s. You can also integrate the .NET technology into self describing documents like XML. For example, you can manipulate XML documents using any one of languages under the .NET Framework. Passport .NET provides a single window access to all Microsoft Resources like Hotmail, Microsoft Chat, MSDN subscriber downloads and others.

1 comment - What do you think?
Posted by Anand Narayanaswamy - May 12, 2009 at 5:40 am

Categories: C#, Channels, Latest   Tags: , , , , , , , , , , , , , , , , , , ,

FAQ 1 – What is Object Oriented Programming?

We deal with objects everyday. There are basically two kinds of objects namely, objects with life and without life. Animals and Human beings form living objects whereas Buildings and Furniture are objects without life. Each of these objects includes certain properties and you can also perform certain actions which ultimately describes their behavior. Object Oriented Programming mainly involves representing objects in a programming language and using them appropriately.

Before learning more about objects you should be aware about the concept of classes. A class represents group of objects of similar kind. Moreover, a class is considered as a template for creating multiple objects with similar features. For example, you can define Hard Disk, Motherboard, CD-ROM Drive and DVD-ROM Drive in a class called Computer. Here each of the computer spares are called as objects. Therefore, you can say that an object is an instance (copy) of a class. In the above case, Hard Disk and Motherboard are an instance of the class Computer and hence they are termed as objects.

All Object Oriented languages shares common set of features such as Encapsulation, Inheritance, and Polymorphism. An object oriented programming language code contains a class definition and its related objects. Hence, they are packaged into some sort of theme and this process is termed as Encapsulation. On the other hand, Inheritance is reusing of the features of one class in another class without defining them. So if you are building applications with large amount of code, you can apply this functionality so that you need not rewrite the whole code from scratch.

Polymorphism means defining different versions of the same code in various versions. The code snippet will be enclosed inside a method. For instance, Addition involves adding of 2 numbers, 3 numbers and so on. Here you are declaring one common situation in different ways. Since C# is an Object Oriented Programming language, it supports all the above features and hence you can apply them while developing C# applications.

Be the first to comment - What do you think?
Posted by Anand Narayanaswamy - May 12, 2009 at 5:36 am

Categories: C#, Channels, Latest   Tags: , , , , , , , , , , , ,

Silverlight in Action

Silverlight is the latest framework developed by Microsoft for building robust visually appealing web applications. Many developers are currently in the process of learning the concepts of Silverlight and hence there is a requirement for a good resource material. Even though the web is scattered with plenty of articles and tutorials, there is no substitute for traditional books. Manning Publications Silverlight in Action by Chad A. Campbell and John Stockton (http://www.manning.com/campbell/) provides a comprehensive coverage of Silverlight with the help of detailed explanation, code samples and screenshots.

Silverlight in Action Chapter 1 provides a nice introduction to Silverlight including the role of developer and designer during the development stage. This chapter also includes a short overview of XAML. Chapter 2 examines the creation and integration of a Silverlight plug-in and also provides a short coverage of Silverlight Application Model and HTML DOM. Chapter 3 examines the layout related aspects such as StackPanel, power grid, display of text, UIEelement and FrameworkElement.

While chapter 4 enables you to interact with users with controls such as Button, Date, chapter 5 provides a detailed coverage of binding data into Silverlight applications with reference to DataGrid and Language Integrated Query (LINQ). Chapter 6 helps you to create Silverlight applications powered with networking functionality. Silverlight is primarily designed to build applications with stunning videos and graphics and chapter 7 examines the related concepts with the help of a mini project. The author demonstrates the application of audios, videos and images in a Silverlight project along with relevant methods and properties in tabular format with associated description.

The next two chapters lay emphasis on graphics and animation such as brushes, transforms, storyboarding and key framing including a short coverage of the usage of Expression Blend. While chapter 10 examines the creation of templates, usage of visual states, VisualStateManager, Chapter 11 provides a detailed analysis of using XAML at runtime, BackgroundWorker and Dynamic Language Runtime (DLR). The final chapter examines the creation of a user control including the usage of a custom splash screen and also provides the required guidelines to host a Silverlight application in a live web server.

The book provides detailed explanation for each concept in an easy to understand manner for the benefit of both beginners and advanced developers. The authors deserve special credit as they have given a screenshot of the final output just above the code snippet in certain chapters. Moreover, the code snippets are marked in relevant places of the analysis which I hope will help readers to understand the techniques very easily.

The complete source code along with two sample chapters is available for download at http://www.manning.com/campbell/. The publisher also maintains a dedicated forum (http://www.manning-sandbox.com/forum.jspa?forumID=369) where you can post queries to the authors. From my point of view, the book will be highly useful for advanced developers but beginners will also find it useful to some extent.

Silverlight in Action is an excellent companion for seasoned .NET buddies

Anand Narayanaswamy, Technical Author/Editor and Microsoft MVP, Learnxpress.com

Be the first to comment - What do you think?
Posted by Anand Narayanaswamy - May 7, 2009 at 12:59 am

Categories: Reviews   Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Next Page »