×
Don’t stop when you’re tired. STOP when you are DONE.
--Your friends at LectureNotes
Close

Dot Net Framework for Application Development

by Prince Rao
Type: NoteInstitute: SAMBRAM INSTITUTE OF TECHNOLOGY Specialization: Computer Science EngineeringDownloads: 5Views: 174Uploaded: 1 month agoAdd to Favourite

Touch here to read
Page-1

Dot Net Framework for Application Development by Prince Rao

Topic:
Prince  Rao
Prince Rao

/ 86

Share it with your friends

Suggested Materials

Leave your Comments

Contributors

Prince  Rao
Prince Rao
Module 1 .Net framework for application development MODULE 1 INTRODUCING MICROSOFT VISUAL C# CHAPTER 1: WELCOME TO C# Writing your first program The Anatomy of a Simple C# program  C# demands that all program logic is contained within a type definition (type is a term referring to a member of the set {class, interface, structure, enumeration, delegate}). Unlike in C(++), in C# it is not possible to create global functions or global points of data.  In its simplest form, a C# program can be written as follows // By convention, C# files end with a *.cs file extension. using System; class HelloClass { public static int Main(string[] args) { Console.WriteLine(“Hello! World”); Console.ReadLine(); return 0; } }  Every executable C# application must contain a class defining a Main() method, which is used to signify the entry point of the application. Mamatha A, Asst Prof, Dept of ISE,SVIT Page 1
Module 1  .Net framework for application development The signature of Main() is adorned with the public and static keywords. Public members are accessible from other types, while static members are scoped at class level and can thus be invoked without the need to first create a new class instance.  C# is the case sensitive programming language.  Main() method has a single parameter, which takes the array of strings. This parameter May contain any number of incoming command line arguments.  You make use of Console class, which is defined within the System namespace. The WriteLine() writes a text string to the standard output. ReadLine() reads a line from standard input until new line character.  The Main() method returns 0 (Success) before exiting. Variations on the Main() Method  Any of the following signatures can be used to define the Main method, assuming it is contained within a C# class or structure definition. // No return type, array of strings as argument. public static void Main(string[] args) { } // No return type, no arguments public static void Main() { } // Integer return type, no arguments public static int Main() { Mamatha A, Asst Prof, Dept of ISE,SVIT Page 2
Module 1 .Net framework for application development } // Integer return type, array of strings as argument. public static int Main(string[] args) { } Processing Command Line Arguments  Assume that you now wish to update HelloClass to process possible command-line parameters  You are checking to see if the array of strings contains some number of items using the Length property of System.Array. As you loop over each item in the array, its value is printed to the console window. class HelloClass { public static void Main(string[] args) { for(int i=0;i<args.Length;i++) Console.WriteLine(“Arg: {0}”, args[i]); } }  As an alternative to for loop, you might iterate the string array using C# foreach loop. class HelloClass { public static void Main(string[] args) { foreach(string s in args) Mamatha A, Asst Prof, Dept of ISE,SVIT Page 3
Module 1 .Net framework for application development Console.WriteLine(s); } }  You are also able to access command line arguments using the static GetCommandLineArgs() method of System.Environment type. The return value of this method is array of strings.  The first index identifies the current directory containing the application itself, while the remaining elements in the array contain the individual command line arguments. public static int Main(string[] args) { ... // Get arguments using System.Environment. string[] arguments = Environment.GetCommandLineArgs(); Console.WriteLine(“Path of the App is {0}”,arguments[0].ToString()); for(int i=1;i<args.Length;i++) Console.WriteLine(“Arg: {0}”, args[i]); ... }  Using namespaces  In the programs above, we have used namespaces like System. It is an existing namespaces in the .NET framework.  We can define our own namespace i.e. user-defined namespace (or custom namespace). Whenever we want to group similar classes into a single entity, we can define a namespace. Mamatha A, Asst Prof, Dept of ISE,SVIT Page 4

Lecture Notes