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

Similar documents
DC69 C# &.NET DEC 2015

.Net Technologies. Components of.net Framework

PES INSTITUTE OF TECHNOLOGY

Darshan Institute of Engineering & Technology for Diploma Studies

A Comparison of Visual Basic.NET and C#

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

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

Object-Oriented Programming

CS260 Intro to Java & Android 03.Java Language Basics

Java Primer 1: Types, Classes and Operators

Chapter 6 Introduction to Defining Classes

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

Introduction To C#.NET

Chapter 1 Getting Started

Java Bytecode (binary file)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

The Java language has a wide variety of modifiers, including the following:

Table of Contents Preface Bare Necessities... 17

A Fourth Look At ML. Chapter Eleven Modern Programming Languages, 2nd ed. 1

Introduction to C# Applications

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

Uka Tarsadia University MCA ( 3rd Semester)/M.Sc.(CA) (1st Semester) Course : / Visual Programming Question Bank

Index COPYRIGHTED MATERIAL

Microsoft Visual Basic 2005: Reloaded

EEE-425 Programming Languages (2013) 1

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS

CMSC 132: Object-Oriented Programming II

Object Oriented Programming in C#

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

UNIT 1. Introduction to Microsoft.NET framework and Basics of VB.Net

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

DC69 C# and.net JUN 2015

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

STRUCTURING OF PROGRAM

Chapter 4 Defining Classes I

Object Orientated Analysis and Design. Benjamin Kenwright

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

1 Shyam sir JAVA Notes

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Object Oriented Pragramming (22316)

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

COP 3330 Final Exam Review

DigiPen Institute of Technology

CS 485 Advanced Object Oriented Design. Enum. Spring 2017

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

Midterm Exam CS 251, Intermediate Programming March 12, 2014

IST311. Advanced Issues in OOP: Inheritance and Polymorphism

Building non-windows applications (programs that only output to the command line and contain no GUI components).

Brief Summary of Java

COPYRIGHTED MATERIAL. Part I The C# Ecosystem. ChapTEr 1: The C# Environment. ChapTEr 2: Writing a First Program

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

S.E. Sem. III [CMPN] Object Oriented Programming Methodology

Introduction to Programming Using Java (98-388)

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

SUN Sun Certified Associate for the Java Platform.

Programming in Visual Basic with Microsoft Visual Studio 2010

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

15CS45 : OBJECT ORIENTED CONCEPTS

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

Lecture 5: Methods CS2301

COP4020 Programming Assignment 1 - Spring 2011

PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO Course: 10550A; Duration: 5 Days; Instructor-led

Absolute C++ Walter Savitch

Class, Variable, Constructor, Object, Method Questions

SPARK-PL: Introduction

엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University COPYRIGHTS 2017 EOM, HYEONSANG ALL RIGHTS RESERVED

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

Part III. Object-Oriented Programming with C#

Chapter 1b Classes and Objects

Notes on Chapter Three

OBJECT ORIENTED PROGRAMMING. Ms. Ajeta Nandal C.R.Polytechnic,Rohtak

3. Java - Language Constructs I

CS313D: ADVANCED PROGRAMMING LANGUAGE

Glossary. For Introduction to Programming Using Python By Y. Daniel Liang

Operators and Expressions

Object Oriented Programming. Solved MCQs - Part 2

Concepts of Programming Languages

Chapter 2: Java OOP I

Functions. x y z. f (x, y, z) Take in input arguments (zero or more) Perform some computation - May have side-effects (such as drawing)

Chapter 9 Enumerations

CSE 142 Su 04 Computer Programming 1 - Java. Objects

Creating and Running Your First C# Program

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

EEE-425 Programming Languages (2013) 1

Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II

C++ Quick Guide. Advertisements

THE CATHOLIC UNIVERSITY OF EASTERN AFRICA A. M. E. C. E. A

C# Fundamentals. Hans-Wolfgang Loidl School of Mathematical and Computer Sciences, Heriot-Watt University, Edinburgh

M4.1-R4: APPLICATION OF.NET TECHNOLOGY

Chapter 6 part 1. Data Types. (updated based on 11th edition) ISBN

Programming: Java. Chapter Objectives. Chapter Objectives (continued) Program Design Including Data Structures. Chapter 7: User-Defined Methods

Checked and Unchecked Exceptions in Java

APCS Semester #1 Final Exam Practice Problems

Learn C# Errata. 3-9 The Nullable Types The Assignment Operators

Syllabus & Curriculum for Certificate Course in Java. CALL: , for Queries

Exam Duration: 2hrs and 30min Software Design

A Foundation for Programming

Practice for Chapter 11

The Decaf Language. 1 Lexical considerations

Transcription:

Q.2 a. What is C#? Discuss its features in brief. 1. C# is a simple, modern, object oriented language derived from C++ and Java. 2. It aims to combine the high productivity of Visual Basic and the raw power of C++. 3. It is a part of Microsoft Visual Studio7.0. 4. Visual studio supports Vb, VC++,C++,Vbscript, Jscript. All of these languages provide access to the Microsft.NET platform. 5..NET includes a Common Execution engine and a rich class library. 6. Microsofts JVM eqiv is Common language run time (CLR). 7. CLR accommadates more than one languages such as C#, VB.NET, Jscript, ASP.NET,C ++. 8. Source code --->Intermediate Language code(il) ---> (JIT Compiler) Native code. 9. The classes and data types are common to all of the.net languages. 10. We may develop Console application, Windows application, Web application using C#. 11. In C# microsoft has taken care of C++ problems such as Memory management, pointers etc. 12. It support garbage collection, automatic memory management and a lot. Q.2b. Draw the.net framework architecture & explain in detail. IETE 1

.Net is not an Operating System. It is a IDE. It provides some functionality for the programmers to build their solution in the most constructive and intelligent way ever. Just to tell you the truth, most of the codes in.net environment resembles with the JAVA coding as if some people coming from Java would find it as to their native language..net is a Framework that loads into your operating system, which you need not to load in the later versions of windows like Windows 2003 server or Just a new release of Windows Vista. As it is going to be added as a component in the next generation of windows. Now, What is the.net all about? Well, Its a framework that supports Common Language Runtime (CLR). As the name suggests, Common Language Runtime will be something that will run a native code for all the programming languages provided within the Architecture. Q.3a. Write a program that employs nested if...else statements to determine that largest of three given numbers. Page Number 101 of Text Book Q.3b. What are increment and decrement operators in C#? Illustrate increment operator with a program. Page Number 68-69 from Text Book Q.4a. What are methods? Write down the basic characteristics of methods? A method is a code block containing a series of statements. Methods must be declared within a class or a structure. It is a good programming practice that methods do only one specific task. Methods bring modularity to programs. Proper use of methods bring the following advantages: Reducing duplication of code Decomposing complex problems into simpler pieces Improving clarity of the code Reuse of code Information hiding Basic characteristics of methods are: IETE 2

Access level Return value type Method name Method parameters Parentheses Block of statements Access level of methods is controlled with access modifiers. They set the visibility of methods. They determine who can call the method. Methods may return a value to the caller. In case our method returns a value, we provide its data type. If not, we use the void keyword to indicate, that our method does not return values. Method parameters are surrounded by parentheses, and separated by commas. Empty parentheses indicate that the method requires no parameters. The method block is surrounded with characters. The block contains one or more statements that are executed, when the method is invoked. It is legal to have an empty method block. A method signature is a unique identification of a method for the C# compiler. The signature consists of a method name, and the type and kind (value, reference, or output) of each of its formal parameters. Method signature does not include the return type. Q.4b. How to use Hash Table, Array List in c#? Explain with example. ArrayList:-Arraylist is a collection of objects(may be of different types). Arraylist is very much similar to array but it can take values of different datatypes. If you want to find something in a arraylist you have to go through each value in arraylist, theres no faster way out.arraylist's size can be changed dynamically. Items are added to the ArrayList with the Add() method. example:-how TO ADD DATA IN ARRAYLIST: using System.Collections; class Program static void Main() Create an ArrayList and add three elements. ArrayList list = new ArrayList(); list.add("one"); list.add("two"); list.add("three"); IETE 3

EXAMPLE-Adding one ArrayList to second one There are different ways to add one ArrayList to another, but the best way is using AddRange. Internally, AddRange uses the Array.Copy or CopyTo methods, which have better performance than some loops. === Program that uses Add and AddRange === using System; using System.Collections; class Program static void Main() Create an ArrayList with two values. ArrayList list = new ArrayList(); list.add(15); list.add(17); Second ArrayList. ArrayList list2 = new ArrayList(); list2.add(110); list2.add(113); Add second ArrayList to first. list.addrange(list2); Display the values. foreach (int i in list) Console.WriteLine(i); === Output of the program === 15 17 IETE 4

110 113 The ArrayList class provides the Count property, which is a virtual property. When you use Count, no counting is actually done; instead, a cached field value is returned HASH TABLE:-Hashtable is also collection which takes a key corresponding to each values. If you want to find something in a hashtable you dont have to go through each value in hashtable, instead search for key values and is faster.the Hashtable lets you quickly get an object out of the collection by using it's key. The Hashtable object contains items in key/value pairs. The keys are used as indexes. We can search value by using their corresponding key. The data type of Hashtable is object and the default size of a Hashtable is 16. Items are added to the Hashtable with the ADD()method. Example-How to add data in hash table:-- Add method of Hashtable is used to add items to the hashtable. The method has index and value parameters. The following code adds three items to hashtable. hshtable.add("a1", "Kamal"); hshtable.add("a2", "Aditya"); hshtable.add("a3", "Ashish"); Retrieving an Item Value from Hashtable The following code returns the value of "Author1" key: string name = hshtable["a1"].tostring(); Removing Items from a Hashtable The Remove method removes an item from a Hashtable. The following code removes item with index "A1" from the hashtable: hshtable.remove("a1"); Looking through all Items of a Hashtable The following code loops through all items of a hashtable and reads the values. Loop through all items of a Hashtable IDictionaryEnumerator en = hshtable.getenumerator(); while (en.movenext()) IETE 5

Q.5a. string str = en.value.tostring(); Write a program to reverse a string in C#.Net. using System; namespace Learn class Program static void Main(string[] args) string Str, Revstr = ""; int Length; Console.Write("Enter A String : "); Str = Console.ReadLine(); Length = Str.Length - 1; while (Length >= 0) Revstr = Revstr + Str[Length]; Length--; Console.WriteLine("Reverse String Is 0", Revstr); Console.ReadLine(); Q.5b. What is enumeration expression in C#? Illustrate through example. The elements of enumeration expressions evaluate the same as their underlying types. In addition to using normal operators, there are additional methods that can be performed with an enum type. An Enum class is used to obtain the majority of functionality shown in this section. Where the Enum class is being used, the capitalized Enum class name prefixes the method call. The examples in this section refer to the following enum: IETE 6

enum Weekday Mon = 1, Tue, Wed, Thu, Fri, Sat = 10, Sun ; As a typed value, the enum must be assigned to a variable of its type. For example, the underlying representation of a Weekday enum may default to an integral value, but it's still a Weekday type. The following line shows the declaration and initialization of an enum variable: Weekday w = Weekday.Mon; During a Console.WriteLine() method call, enum values are printed with their names rather than their underlying integral values. Here's an example: Console.WriteLine("WeekDay: 0", w); WeekDay: Mon The Format() method returns the string representation of an enum value, as shown here: Console.WriteLine("Format: 0", w.format()); Format: Mon To go in the opposite direction and convert a string to an enum, use the FromString() method. The arguments it accepts are the enum type, the string representation of the value to be converted, and a Boolean condition to verify case. The following example uses the typeof() operator to get the enum type. The string to be converted is Tue, and the method is case-sensitive. Console.WriteLine("FromString: 0", Enum.FromString(typeof(EnumTest.Weekday), "Tue", true)); FromString: Tue To get the name of an enum variable, use the GetName() method. The following example shows the GetName() method accepting the enum type and an instance of that enum type and returning its name as a string. w = EnumTest.Weekday.Wed; Console.WriteLine("GetName: 0", Enum.GetName(typeof(EnumTest.Weekday), w)); GetName: Wed If there is a need to get the string representations of all the members of an enum, use the GetNames() method plural of the previous method. The following example shows an array being filled with the names. The method call only needs the enum type. string[] weekdays = new string[7]; weekdays = Enum.GetNames(typeof(EnumTest.Weekday)); Console.WriteLine("Day 1: 0", weekdays[0]); Day 1: Mon Console.WriteLine("Day 2: 0", weekdays[1]); Day 2: Tue Console.WriteLine("Day 3: 0", weekdays[2]); Day 3: Wed IETE 7

Console.WriteLine("Day 4: 0", weekdays[3]); Day 4: Thu Console.WriteLine("Day 5: 0", weekdays[4]); Day 5: Fri Console.WriteLine("Day 6: 0", weekdays[5]); Day 6: Sat Console.WriteLine("Day 7: 0", weekdays[6]); Day 7: Sun A corresponding method to get the values of an enum is the GetValues() method. The following example shows the GetValues() method accepting an enum type and returning an array of objects. Notice that the array is of type objects. In C#, all types are also object types. Therefore, any type can be assigned to the object type. object[] weekdayvals = new object[7]; weekdayvals = Enum.GetValues(typeof(EnumTest.Weekday)); Console.WriteLine("Day 1: 0", weekdayvals[0]); Day 1: Mon Console.WriteLine("Day 2: 0", weekdayvals[1]); Day 2: Tue Console.WriteLine("Day 3: 0", weekdayvals[2]); Day 3: Wed Console.WriteLine("Day 4: 0", weekdayvals[3]); Day 4: Thu Console.WriteLine("Day 5: 0", weekdayvals[4]); Day 5: Fri Console.WriteLine("Day 6: 0", weekdayvals[5]); Day 6: Sat Console.WriteLine("Day 7: 0", weekdayvals[6]); Day 7: Sun To find out the underlying type of an enum, use the GetUnderlyingType() method. It accepts an enum type argument, and the return value is the integral type of the enum's underlying type. Here's an example: Console.WriteLine("Underlying Type: 0", Enum.GetUnderlyingType( typeof(enumtest.weekday))); Underlying Type: Int32 When it's necessary to determine if an enum value is defined, use the IsDefined() method. It accepts an enum type and an enum value and returns a Boolean true if the value is defined in the enum. Otherwise, it returns false. Here's an example: w = EnumTest.Weekday.Thu; Console.WriteLine("Thu is Defined: 0", Enum.IsDefined(typeof(EnumTest.Weekday), w)); Thu is Defined: True To obtain an enum type that is set to a specific value, use the ToObject() method. The following example shows the method accepting an enum type and an integer, and returning an enum of the requested type with the value corresponding to the integer. Console.WriteLine("Get Friday: 0", Enum.ToObject(typeof(EnumTest.Weekday), 5)); Get Friday: Fri IETE 8

Q.6a. Q.6b. Q.6c. Explain the three basic principles of OOPs. Page Number 247 of the Text book What is the difference between class & subclass? Page Number 286 of the Text book Write a program to illustrate a simple inheritance. Page No 286 of the Text book Q.8a. What is the need of operator overloading? Give examples of overloading unary operators, overloading binary operators, overloading comparison operators. Operator overloading is a concept of polymorphism where you can redefine operators like +,, * etc with additional functionalities. For instance we can redefine the + functionalities to add objects like obj1 + obj2. Below is simple code snippet which redefines + operator. class SomeClass private int somevalue; public SomeClass(int val) somevalue = val; public static SomeClass operator +(SomeClass arg1, SomeClass arg2) IETE 9

return new SomeClass(arg1.someValue + arg2.somevalue); You can now use the + operator to add objects of type someclass as shown in the below code snippet. Obj = obj1 = obj2 Q.9b. What is thread? What does it do? What is the use of threading in C#? Page Number 439 of text book Text Book Programming in C# -A primer, E Balagurusamy, II Edition, TMH, 2008 IETE 10