×
There is no substitute for HARD WORK.
--Your friends at LectureNotes
Close

Note for Dot Net Framework for Application Development - DFAD By Prabhat Rao

  • Dot Net Framework for Application Development - DFAD
  • Note
  • SAMBRAM INSTITUTE OF TECHNOLOGY - SaIT
  • Computer Science Engineering
  • 9 Topics
  • 1127 Views
  • 42 Offline Downloads
  • Uploaded 1 year ago
Prince  Rao
Prince Rao
0 User(s)
Download PDFOrder Printed Copy

Share it with your friends

Leave your Comments

Text from page-2

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

Text from page-3

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

Text from page-4

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

Text from page-5

Module 1  .Net framework for application development Assume we need to develop a program to show the features of several vehicles like car, bus and bike. Then, the classes for all these vehicles can be put under a namespace like – namespace Vehicle { public class Car { //members of Car class } public class Bus { //members of Bus class } public class Bike { //members of Bike class } } Now, the namespace Vehicle acts as a container for all these classes. If we want to create an object of any of these classes in any other application, we can simply write – using System; using Vehicle; //note this class Test { public static void Main() { Car c=new Car(); ------------} } Mamatha A, Asst Prof, Dept of ISE,SVIT Page 5

Lecture Notes