NOIDATUT E Leaning Platform

Similar documents
Introduction to.net, C#, and Visual Studio. Part I. Administrivia. Administrivia. Course Structure. Final Project. Part II. What is.net?

Introduce C# as Object Oriented programming language. Explain, tokens,

DAD Lab. 1 Introduc7on to C#

C#: framework overview and in-the-small features

3. Basic Concepts. 3.1 Application Startup

C# Java. C# Types Naming Conventions. Distribution and Integration Technologies. C# C++.NET A C# program is a collection of: C C++ C# Language

Distribution and Integration Technologies. C# Language

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class.

Introduction To C#.NET

Object-Oriented Programming

C#.Net. Course Contents. Course contents VT BizTalk. No exam, but laborations

Chapter 1 Getting Started

IT 528 Developing.NET Applications Using C# Gülşen Demiröz

This tutorial has been prepared for the beginners to help them understand basics of c# Programming.

C++\CLI. Jim Fawcett CSE687-OnLine Object Oriented Design Summer 2017

Introduction to C# Applications

EEE-425 Programming Languages (2013) 1

What property of a C# array indicates its allocated size? What keyword in the base class allows a method to be polymorphic?

.Net Technologies. Components of.net Framework

Cloning Enums. Cloning and Enums BIU OOP

UNIT I An overview of Programming models Programmers Perspective

Computing is about Data Processing (or "number crunching") Object Oriented Programming is about Cooperating Objects

Saikat Banerjee Page 1

Objectives. Describe ways to create constants const readonly enum

Inheritance and Polymorphism

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

A Comparison of Visual Basic.NET and C#

Introduction to Programming Using Java (98-388)

SWE344. Internet Protocols and Client-Server Programming

C# Types. Industrial Programming. Value Types. Signed and Unsigned. Lecture 3: C# Fundamentals

Visual Studio.NET.NET Framework. Web Services Web Forms Windows Forms. Data and XML classes. Framework Base Classes. Common Language Runtime

Industrial Programming

C# in Unity 101. Objects perform operations when receiving a request/message from a client

Agenda: Discussion Week 7. May 11, 2009

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am

CIS 110: Introduction to Computer Programming

Outline. CIS 110: Introduction to Computer Programming. Any questions? My life story. A horrible incident. The awful truth

Programming II (CS300)

Getting started 7. Storing values 21. Creating variables 22 Reading input 24 Employing arrays 26 Casting data types 28 Fixing constants 30 Summary 32

PES INSTITUTE OF TECHNOLOGY

2. A GUI A. uses buttons, menus, and icons B. should be easy for a user to manipulate C. both (a) and (b) D. stands for Graphic Use Interaction

CLASSES AND OBJECTS IN JAVA

C# Frequently Asked Questions for C++ programmers

EXAM Microsoft MTA Software Development Fundamentals. Buy Full Product.

POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors

POLYMORPHISM 2 PART. Shared Interface. Discussions. Abstract Base Classes. Abstract Base Classes and Pure Virtual Methods EXAMPLE

Framework Fundamentals

Extending Classes (contd.) (Chapter 15) Questions:

PES INSTITUTE OF TECHNOLOGY (BSC) V MCA, Second IA Test, OCTOBER 2017 Programming Using C#.NET (13MCA53) Solution Set Faculty: Jeny Jijo

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

DigiPen Institute of Technology

6.096 Introduction to C++ January (IAP) 2009

Trusted Components. Reuse, Contracts and Patterns. Prof. Dr. Bertrand Meyer Dr. Karine Arnout

DAD Lab. 2 Additional C# Topics

Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain

Module 6: Fundamentals of Object- Oriented Programming

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

JaCIL: A CLI to JVM Compiler Technical Report. Almann T. Goo Rochester Institute of Technology Department of Computer Science

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

CS3157: Advanced Programming. Outline

C#, Visual Basic, C++/CLI, and F#

Chapter 5 Object-Oriented Programming

Modern Programming Languages. Lecture Java Programming Language. An Introduction

Developing Microsoft.NET Applications for Windows (Visual Basic.NET)

12/14/2016. Errors. Debugging and Error Handling. Run-Time Errors. Debugging in C# Debugging in C# (continued)

C# Language Object-oriented Programming Basics

Table of Contents Preface Bare Necessities... 17

Understand Computer Storage and Data Types

LEARN WITH INTRODUCTION TO TYPESCRIPT

DC69 C# &.NET JUNE C# is a simple, modern, object oriented language derived from C++ and Java.

PES INSTITUTE OF TECHNOLOGY (BSC) V MCA, Second IA Test, September 2014

Brief Summary of Java

CE221 Programming in C++ Part 1 Introduction

Short Notes of CS201

Advanced Object-Oriented Programming. 11 Features. C# Programming: From Problem Analysis to Program Design. 4th Edition

CGS 2405 Advanced Programming with C++ Course Justification

Functional programming in C#

EL2310 Scientific Programming

COP 3330 Final Exam Review

CS201 - Introduction to Programming Glossary By

CS105 C++ Lecture 7. More on Classes, Inheritance

CS349/SE382 A1 C Programming Tutorial

JAVA OBJECT-ORIENTED PROGRAMMING

Object-Oriented Programming in C# (VS 2015)

Object Oriented Programming CS250

CS313D: ADVANCED PROGRAMMING LANGUAGE

Java Object Oriented Design. CSC207 Fall 2014

COPYRIGHTED MATERIAL. Visual Basic 2008 Core Elements

EVALUATION COPY. Unauthorized reproduction or distribution is prohibitied C# ESSENTIALS

COPYRIGHTED MATERIAL. Contents. Part I: C# Fundamentals 1. Chapter 1: The.NET Framework 3. Chapter 2: Getting Started with Visual Studio

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

04-24/26 Discussion Notes

Inheritance, and Polymorphism.

IST311. Advanced Issues in OOP: Inheritance and Polymorphism

Programming II (CS300)

EAServer 6.1 New Features Guide

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

VISUAL PROGRAMMING_IT0309 Semester Number 05. G.Sujatha & R.Vijayalakshmi Assistant professor(o.g) SRM University, Kattankulathur

OBJECT ORIENTED PROGRAMMING

CPSC 427: Object-Oriented Programming

Transcription:

NOIDATUT E Leaning Platform Dot Net Framework Lab Manual COMPUTER SCIENCE AND ENGINEERING Presented by: NOIDATUT Email : e-learn@noidatut.com www.noidatut.com

C SHARP 1. Program to display Hello World in C Sharp 2. Program to illustrate Comments in C Sharp 3. Program to illustrate Data Types in C Sharp 4. Program to illustrate Ennumerations in C Sharp 5. Program to illustrate Arrays in C Sharp 6. Program to illustrate variables and constant 7. Program to illustrate Expressions in C Sharp 8. Program to illustrate loops and statements in C Sharp 9. Program to illustrate structures in C Sharp 10. Program to illustrate Class in C Sharp 11. Program to illustrate abstract Class in C Sharp 12. Program to implement inheritance in C Sharp 13. Program to illustrate exception handling in C Sharp 14. Program to create custom exception handling in C Sharp 15. Program to illustrate the use of delegates in C Sharp 16. Program to illustrate the use of events in C Sharp C SHARP LAB MANUAL 2 1. Program to display Hello World in C Sharp using System; public class HelloWorld

public static void Main() Console.WriteLine("Hello World in C#"); C# classes are stored in.cs files. After you have saved the preceding program in a file, let's say Hello World, you can compile the program into a.net executable. You will need to include the.net Framework SDK's bin folder in your PATH variable. If you have installed Visual Studio.NET, you have a shortcut under Visual Studio.NET Tools called Visual Studio.NET 2003 Command Prompt. This shortcut initializes all the environment variables and provides access to the command-line compilers as well. csc HelloWorld.cs Now enter HelloWorld.exe to run the application, and you should see "Hello World in C#" echoed on the screen WWW.NOIDATUT.COM C SHARP LAB MANUAL 3 2. Program to illustrate Comments in C Sharp using System; / <summary> / A Simple Class / </summary>

public class Comments public static void Main() / A Simple comment /* A multi line comment */ C#"); Console.WriteLine("Hello World in NOIDATUT.COM - E LEARNING PLATFORM C SHARP LAB MANUAL 4 3. Program to illustrate Data Types in C Sharp C# Type Corresponding.NET Framework Type Bool System.Boolean

byte, sbyte Char System.Byte, System.SByte System.Char decimal, double, System.Decimal, System.Double, Single short, ushort, System.Single System.Int16, System.UInt16, int, uint, long, System.Int32, System.UInt32, Ulong Object String System.Int64, System.UInt64 System.Object System.String C SHARP LAB MANUAL 5 4. Program to illustrate Ennumerations in C Sharp using System; public class UseEnumerations

enum CreditCard Visa = 0, MasterCard = 1, AmericanExpress = 2, Discover = 3 public static void Main() CreditCard mycard = CreditCard.Discover; Console.WriteLine(mycard); Console.WriteLine((int) mycard); C SHARP LAB MANUAL 6 5. Program to illustrate Arrays in C Sharp using System; public class UseArrays public static void Main()

String[] days_of_week = "Sunday", ; "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" foreach (string day in days_of_week) Console.WriteLine(day); C SHARP LAB MANUAL 7 6. Program to illustrate variables and constant Variables and Constants Simple value types can be assigned using the variable = value construct, whereas reference types are required to use the new keyword for creating a new instance. using System;

public class UseVariables public static void Main() const string HELLO_WORLD = "Hello World"; string message = HELLO_WORLD+ " in C#"; MyClass mc = new MyClass(message); mc.print(); public class MyClass private String message; public MyClass(String message) this.message = message; C SHARP LAB MANUAL 8 public void Print() Console.WriteLine(message);

C SHARP LAB MANUAL 9 7. Program to illustrate Expressions in C Sharp Expressions in C# are very similar to those provided by Java and C+ + programming languages. using System;

public class UseExpressions public static void Main() int a = 10; int b = 10; int result = a * b; bool check = (a == b); Console.WriteLine(result); Console.WriteLine(check); C SHARP LAB MANUAL 10 8. Program to illustrate loops and statements in C Sharp As expected, the C# programming language includes several procedural programming constructs, including if-else, for loop, while loop, switch statements, and so on.

using System; public class UseStatements public static void Main() string[] message = "Hello", "World", "in", "C#"; foreach (string msg in message) Console.Write(msg+" "); Console.WriteLine(""); int a = 10; int b = 20; if (a < b) C SHARP LAB MANUAL 11 Console.WriteLine("a<b"); else Console.WriteLine("a>=b");

C SHARP LAB MANUAL 12 9. Program to illustrate structures in C Sharp Structures are simply an aggregation of value types and are allocated on the stack and not on the heap. Structures are useful for passing a logical and related set of data values. Structures don't support inheritance but can implement interfaces. For instance, the following program would print Hitesh.Seth followed by John.Doe and illustrates that structures are not reference types.

using System; public class UseStructures public static void Main() Person hs = new Person("Hitesh","Seth"); Person jd = hs; jd.firstname = "John"; jd.lastname = "Doe"; Console.WriteLine(hs.FirstName+"."+hs.LastName); Console.WriteLine(jd.FirstName+"."+jd.LastName); C SHARP LAB MANUAL 13 public struct Person public string FirstName, LastName; public Person(string FirstName, string LastName)

this.lastname = LastName; this.firstname = FirstName; C SHARP LAB MANUAL 14 10. Program to illustrate Class in C Sharp Classes, on the other hand, are reference types and hence are allocated on the heap. Classes provide object-oriented constructs such as encapsulation, polymorphism, and inheritance. For instance, the following program would print John.Doe twice, illustrating that objects are reference types, allocated on the heap.

using System; public class UseClasses public static void Main() Person hs = new Person("Hitesh","Seth"); Person jd = hs; jd.firstname = "John"; jd.lastname = "Doe"; Console.WriteLine(hs.GetFullName()); Console.WriteLine(jd.GetFullName()); C SHARP LAB MANUAL 15 public class Person private string sfirstname, slastname; public Person(string FirstName, string LastName)

this.sfirstname = FirstName; this.slastname = LastName; public string FirstName get set return sfirstname; sfirstname = value; public string LastName get C SHARP LAB MANUAL 16 return slastname; set

slastname = value; public String GetFullName() return this.firstname + "."+ this.lastname; C SHARP LAB MANUAL 17 11. Program to illustrate Inheritance in Class in C Sharp Classes provide inheritance capability, which allows the derived class to inherit the functionality of a base class and potentially override some of the methods. A class definition consists of constructors and destructors, members, methods, properties, and events. (You will learn more about events later in this section.) Unlike the Java programming language, in

C# all methods that are overridden must be marked as virtual in the base class. The is operator provides runtime validation if an object is of a particular type. For instance, the following program will return that a FullPerson object is always a Person. using System; namespace hks public class UseInheritance public static void Main() FullPerson hs = new FullPerson("Hitesh","K","Seth"); Console.WriteLine(hs.GetFullName()); Object ohs = hs; if (ohs is Person) C SHARP LAB MANUAL 18 Console.WriteLine("I am still a Person"); public class Person

public string FirstName, LastName; public Person(string FirstName, string LastName) this.firstname = FirstName; this.lastname = LastName; public virtual string GetFullName() return this.firstname + "." + this.lastname; public class FullPerson : Person public string MiddleInitial; C SHARP LAB MANUAL 19 public FullPerson(string FirstName, string MiddleInitial, base(firstname,lastname) string LastName) : this.middleinitial = MiddleInitial;

public override string GetFullName() return this.firstname + "." + this.middleinitial + "." + this.lastname; C SHARP LAB MANUAL 20 12. Program to illustrate abstract Class in C Sharp Classes can also be marked as either abstract, which means they have to be subclassed for any instances to be created, or sealed, which does not allow any subclassing. Using Abstract Classes (C#)

using System; public class UseAbstractClasses public static void Main() Person hs = new Person("Hitesh","Seth"); Console.WriteLine(hs.GetFullName()); abstract public class Abstract protected string FirstName, LastName; public Abstract(string FirstName, string LastName) this.firstname = FirstName; this.lastname = LastName; abstract public string GetFullName(); public class Person : Abstract

public Person(string FirstName, string LastName) : base(firstname, LastName) public override string GetFullName() return FirstName+"."+LastName; C SHARP LAB MANUAL 22 13. Program to implement inheritance in C Sharp C# provides the concept of interfaces. Interfaces really represent a signature of what needs to be implemented by a derived class. C# supports multiple inheritances of interfaces using System;

public class UseInterfaces public static void Main() Person hs = new Person(); hs.name = "Hitesh Seth"; hs.address = "1 Executive Drive, City, NJ 08520"; Console.WriteLine(hs.GetName()); Console.WriteLine(hs.GetAddress()); public interface IName string GetName(); C SHARP LAB MANUAL 23 public interface IAddress string GetAddress(); public class Person : IName, IAddress private string name, address; public Person()

public string Name set name = value; public string Address set address = value; C SHARP LAB MANUAL 24 public string GetName() return name; public string GetAddress() return address;

C SHARP LAB MANUAL 25 14. Program to illustrate exception handling in C Sharp C# provides robust exception handling capabilities. For instance, the program that follows catches the exception at runtime and allows messages to be displayed to the end user without requiring an intermediate exit. using System;

public class UseExceptions public static void Main() try int a = 10; int b = 10; int c = a/(a-b); catch (Exception ex) Console.WriteLine("Exception Caught"); Console.WriteLine(ex.Message); C SHARP LAB MANUAL 26

C SHARP LAB MANUAL 2 7 15. Program to create custom exception handling in C Sharp Custom exceptions, which contain more information related to the underlying application, can also be created. Custom exceptions derive from the System.Exception class. Creating Custom Exceptions (C#) using System;

public class UseCustomExceptions public static void Main() try Discount big_discount = new Discount(56); catch (TooBigDiscountException ex) Console.WriteLine("Exception Caught"); Console.WriteLine(ex.Message); C SHARP LAB MANUAL 28 public class Discount private int percent; public Discount(int percent) this.percent = percent; if (percent > 50) throw new

TooBigDiscountException("Discount > 50%"); public class TooBigDiscountException : Exception public TooBigDiscountException(String msg) : base (msg) C SHARP LAB MANUAL 29 16. Program to illustrate the use of delegates in C Sharp Delegates give C# programmers the capability of function pointers, basically passing a function as a parameter. using System; public class UseDelegates public delegate void MyDelegate(string message);

public static void Main() String message = "Hello Delegates"; MyDelegate d1 = new MyDelegate(PrintOnce); MyDelegate d2 = new MyDelegate(PrintTwice); d1(message); d2(message); public static void PrintOnce(String message) Console.WriteLine(message); C SHARP LAB MANUAL 30 public static void PrintTwice(String message) Console.WriteLine("1."+message); Console.WriteLine("2."+message);

C SHARP LAB MANUAL 31 16. Program to illustrate the use of events in C Sharp A typical use of delegates is in event handling. For instance, take a look at Listing 3.5. It defines a class called Button, which has a Delegate called EventHandler. Event handlers can be assigned for the event OnClick and allow the calling application to pass in the reference of the method Button_Click as the callback method to invoke after the button is clicked. Using Events (C#) using System; public class Events public static void Main()

Button button = new Button(); button.onclick+= new Button.EventHandler(Button_Click) ; button.click(); public static void Button_Click() Console.WriteLine("Button Clicked"); C SHARP LAB MANUAL 31 public class Button public delegate void EventHandler(); public event EventHandler OnClick; public void Click() OnClick();