INTERNAL ASSESSMENT TEST 1 ANSWER KEY

Similar documents
PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science And Engineering

vtuplanet.com C#Programming with.net C# Programming With.NET (06CS/IS761)

CHAPTER 2: BUILDING C# APPLICATIONS

BUILDING C# APPLICATIONS

PES INSTITUTE OF TECHNOLOGY

UNIT I An overview of Programming models Programmers Perspective

This lecture notes is prepared according to the syllabus of the following subjects

A NET Refresher

Module 2: Introduction to a Managed Execution Environment

Vtusolution.in C# PROGRAMMING AND.NET. Subject Code: 10IS761/10CS761 I.A. Marks : 25 Hours/Week : 04 Exam Hours: 03 Total Hours : 52 Exam Marks: 100

Chapter 12 Microsoft Assemblies. Software Architecture Microsoft Assemblies 1

Objective of the Course: (Why the course?) Brief Course outline: (Main headings only) C# Question Bank Chapter1: Philosophy of.net

UNIT-1 The Philosophy of.net

Chapter 1 Getting Started

New programming language introduced by Microsoft contained in its.net technology Uses many of the best features of C++, Java, Visual Basic, and other

Department of Computer Applications

1. Introduction to the Common Language Infrastructure

Chapter 4 Defining Classes I

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


Appendix G: Writing Managed C++ Code for the.net Framework

S.Sakthi Vinayagam Sr. AP/CSE, C.Arun AP/IT

INTRODUCTION TO.NET. Domain of.net D.N.A. Architecture One Tier Two Tier Three Tier N-Tier THE COMMON LANGUAGE RUNTIME (C.L.R.)

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

Unit 1: Visual Basic.NET and the.net Framework

UNIT V *********************************************************************************************

C# Programming in the.net Framework

Programming in Visual Basic with Microsoft Visual Studio 2010

INFORMATICS LABORATORY WORK #2

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

KINGS COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING ACADEMIC YEAR (ODD SEMESTER) QUESTION BANK

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

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

Top 40.NET Interview Questions & Answers

12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension.

3A01:.Net Framework Security

M4.1-R4: APPLICATION OF.NET TECHNOLOGY

Compiling and Running an Application from the Command Line

.Net Technologies. Components of.net Framework

CHAPTER 7 COM and.net

Assemblies. necessary and sufficient to make that file self describing. This unit is called Assembly.

Chapter 10. Class & Objects in JAVA. By: Deepak Bhinde PGT Com.Sc.

.Net Interview Questions

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

Saikat Banerjee Page 1

The Microsoft.NET Framework

DOT NET Syllabus (6 Months)

UNIT 1 PART A PART B

Introduction to Programming Using Java (98-388)

Using COM and COM+ in.net -P/invoke: The mechanism to call unmanaged functions in Win32 DLLs from.net

Microsoft..NET Framework. Overview

University of West Bohemia in Pilsen. Faculty of Applied Sciences. Department of Computer Science and Engineering DIPLOMA THESIS

C# Syllabus. MS.NET Framework Introduction

Microsoft Visual Basic 2005: Reloaded

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

Introduction to.net Framework

EEE-425 Programming Languages (2013) 1

Authoring Installations for Microsoft s.net Framework

B.E /B.TECH DEGREE EXAMINATIONS,

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism

Darshan Institute of Engineering & Technology for Diploma Studies

Chapter 1: A First Program Using C#

Building Windows Applications with.net. Allan Laframboise Shelly Gill

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

Component models. Page 1

What is ASP.NET? ASP.NET 2.0

Object-Oriented Programming

C# 6.0 in a nutshell / Joseph Albahari & Ben Albahari. 6th ed. Beijin [etc.], cop Spis treści

Cookbook for using SQL Server DTS 2000 with.net

PESIT- Bangalore South Campus Hosur Road (1km Before Electronic city) Bangalore

Fundamental C# Programming

AC73/AT73 C# &.NET DEC 2015

An Introduction to.net for the J2EE Programmer

Learning to Program in Visual Basic 2005 Table of Contents

Programming in C# for Experienced Programmers

The C# Language PART I. CHAPTER 1: Introducing C# CHAPTER 2: Writing a C# Program. CHAPTER 3: Variables and Expressions. CHAPTER 4: Flow Control

HCIM SUMMER WORKSHOP Introduction to C#

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

Demo: Controlling.NET Windows Forms from a Java Application. Version 8.2


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

Building, Packaging, Deploying, and Administering Applications and Types

MSIT-120: Dot Net Technologies

.NET-6Weeks Project Based Training

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

COPYRIGHTED MATERIAL PART I. CHAPTER 1: Introducing C# CHAPTER 2: Writing a C# Program. CHAPTER 3: Variables and Expressions. CHAPTER 4: Flow Control

.NET CLR Framework. Unmanaged Hosts - Assembly Access

Introduction to Programming Microsoft.NET Applications with Visual Studio 2008 (C#)

CS112 Lecture: Defining Instantiable Classes

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

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

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

High-Level Language VMs

Preview from Notesale.co.uk Page 3 of 36

Pace University. Fundamental Concepts of CS121 1

CS1004: Intro to CS in Java, Spring 2005

JAVA: A Primer. By: Amrita Rajagopal

Expert C++/CLI:.NET for Visual C++ Programmers

Introduction To C#.NET

Chapter 1:- Introduction to.net. Compiled By:- Ankit Shah Assistant Professor, SVBIT.

Transcription:

INTERNAL ASSESSMENT TEST 1 ANSWER KEY Subject & Code: C# Programming and.net-101s761 Name of the faculty: Ms. Pragya Q.No Questions 1 a) What is an assembly? Explain each component of an assembly. Answers:- Marks 5 Assembly is really a logical grouping of one or more related modules that are intended to be deployed and versioned as a single unit. When a *.dll or *.exe has been created using a.net-aware compiler, the resulting module is bundled in to an "assembly." Regardless of which.net language you choose to program with,.net binaries take the same file extension as classic COM binaries (*.dll or *.exe), they have absolutely no internal similarities. Building a.net *.dll, it is to consider that the binary and the assembly are one and the same. Building a.net *.exe desktop application, the *.exe can simply be referred to as the assembly itself. For example, *.dll.net binaries do not export methods to facilitate communications with the classic COM runtime (given that.net is not COM). Furthermore,.NET binaries are not described using IDL and are not registered into the system registry. Perhaps most important, unlike classic COM servers,.net binaries do not contain platform-specific instructions, but rather platform-agnostic "intermediate language" (IL). Components of assembly a) Assemblies also contain metadata that describes in vivid detail the characteristics of every "type" living within the binary. For example, if you have a class named Car contained within a given assembly, the type metadata describes details such as Car's base class, which interfaces are implemented by Car (if any), as well as a full description of each member supported by the Car type. b) An assembly contains CIL code which is conceptually similar to java byte code in that it is not compiled to platform specific instructions until absolutely necessary. Typically "absolutely necessary" is the point at which a block of CIL instructions are referenced for use by the.net runtime engine. c) Assemblies themselves are also described using metadata, which is officially termed a manifest. The manifest contains information about the current version of the assembly, culture information (used for localizing string and image resources), and a list of all externally b) What is the difference between single file and multi file assemblies? 5 Answers:- Assembly is really a logical grouping of one or more related modules that are intended to be deployed and versioned as a single unit. If an assembly is composed of a single *.dll or *.exe module, you have a "single file assembly." Single file assemblies contain all the necessary CIL, metadata and associated manifest in an autonomous, single, well-defined

package. Multifile assemblies, on the other hand, are composed of numerous.net binaries, each of which is termed a module. When building a multifile assembly, one of these modules, termed the primary module, must contain the assembly manifest and possibly CIL instructions and metadata for various types. The other related modules contain a module level manifest, CIL and type metadata. When an assembly is partitioned into discrete modules, we end up with a more flexible deployment option. For example, if a user is referencing a remote assembly that needs to be downloaded onto his or her machine, the runtime will only download the required modules. Therefore, you are free to construct your assembly in such a way that less frequently required types, such as a type named HardDriveReformatter are kept in a separate standalone module. In contrast, if all your types were placed in a single file assembly, the end user may end up downloading a large chunk of data that is not really needed and which is obviously a waste of time. 2 a) What are the building blocks of.net platform? Briefly explain the role of following 10 i) CLS ii) CTS iii) CLR iv) Base class libraries. Answers:- The building blocks of.net are:- a) CLR b) CTS, c) CLS. i) CLS: - The Common Language Specification (CLS) is a set of rules that define a subset of common types and programming constructs that all.net programming languages can agree on. Thus, if we build.net types that only expose CLScompliant features, you can rest assured that all.net-aware languages could make use of your types. Conversely, if you make use of a data type or BE ISE IV Semester 2

programming construct that is outside of the CLS, you cannot guarantee that every.net programming language can interact with your binary code library. The CLS is a set of guidelines that describe in vivid detail, the minimal and complete set of features a given.net-aware compiler must support to produce code that can be hosted by the CLR, while at the same time be accessed in a uniform manner by all languages that target the.net platform. In many ways the CLS can be viewed as a physical subset of the full functionality defined by the CTS. The CLS is ultimately a set of rules that compiler builders must conform to, if they intend their ii) CTS: - Another building block of the.net platform is the Common Type System, or CTS. The CTS fully describes all possible data types and programming constructs supported by the runtime, specifies how these entities can interact with each other and details how they are represented in the.net metadata format. Common Type System (CTS) is a formal specification that describes how a given type i.e. class, structure, interface, etc. must be defined in order to be hosted by the CLR. Understand that a given.net-aware language might not support each and every entity defined by the CTS. iii) CLR: - The runtime layer is properly referred to as the common language runtime, or CLR. The primary role of the CLR is to locate, load, and manage.net types on your behalf. The CLR also takes care of a number of low-level details such as automatic memory management, language integration, and ensuring type safety. Runtime can be referred to as a collection of external services that are required to execute a given compiled unit of code. When an assembly is referenced for use, mscoree.dll is loaded automatically, which in turn loads the required assembly into memory. The runtime engine is responsible for a number of tasks. First and foremost, it is the entity in charge of resolving the location of an assembly and finding the requested type (e.g., class, interface, structure, etc.) within the binary by reading the contained metadata. The execution engine lays out the type in memory, compiles the associated CIL into platform-specific instructions, performs any (optional) security checks and then executes the code in question. iv) Base class libraries: - the.net platform provides a base class library that is available to all.net programming languages. Not only does this base class library encapsulate various primitives such as threads, file IO, graphical rendering and interaction with various hardware devices, but it also provides support for a number of services required by most real-world applications. For example, the base class libraries define types that facilitate database manipulation, XML integration, programmatic security, and the construction of Web-enabled (as well as traditional desktop and console based front ends. 3 a) Explain how csc.exe compiler is used to build c # application. Explain any five flags with appropriate examples. 10 answers: - We can compile our.net assemblies using the stand-alone compiler, csc.exe. now that development machine recognizes csc.exe as sdk(software development kit) for.net has been installed and path variables is set, the next goal is to build a simple single file assembly named testapp.exe using the raw c# compiler. first, some source code is written.

open a text editor (notepad.exe is fine), and enter the source code as shown in following example once finished, save the file by the name of the class containing the main method i.e. testapp.cs, with.cs extension. to compile testapp.cs into a console application named textapp.exe, you would use the following command set csc testapp.cs or csc /target:exe testapp.cs or csc /t:exe testapp.cs given that the /t:exe flag is the default output used by the c# compiler, we can compile without using target flag also. both results to the same thing. flags which are used while compiling the program in c# are as follows: - Examples: - For the above source code example, if we need to compile the code and get the output by some other name then we use out option. Here, the file name is TestApp.cs but when the file is compiled the output file will have the name as Test.cs. csc /out Test.cs TestApp.cs BE ISE IV Semester 2

For the above source code example, if we need to compile the code and get the output as a library file then we use the following option csc /target:library TestApp.cs For the above source code example, if we need to compile the code and get the output as a module file then we use the following option csc /target:module TestApp.cs 4 a) Is it necessary to make Main( ) method as static? Justify your answer, with example. 5 Answers: - Yes, it is necessary to make main method as static. When a method is marked with the "static" keyword, it may be called directly from the class level, and does not require an object variable. For this very reason, Main() is declared static to allow the runtime to invoke this function without needing to allocate a new instance of the defining class. If we use static keyword before any method name to make it static than it means no object variable is required to access that method. In the above example main method has been defined static so, no new instance is required to access this main method. It can be directly accessed by the compiler. b) Explain the concept of namespaces. Explain with example. 5 Answers: - It is worth reiterating that a namespace is nothing more than a convenient way for us to logically understand and organize related types. As you build your custom types, you have the option of organizing your items into a custom namespace. Again, a namespace is a logical naming scheme used by.net languages to group related types under a unique umbrella. When you group your types into a namespace, you provide a simple way to circumvent possible name clashes between assemblies. For example, if you were building a new Windows Forms application that references two external assemblies, and each assembly contained a type named GoCart, you would be able to specify which GoCart class you are interested in by appending the type name to its containing namespace Assume you are developing a collection of geometric classes named Square, Circle, and

Hexagon. Given their similarities, you would like to group them all together into a shared custom namespace. You have two basic approaches. First, you may choose to define each class within a single file (shapeslib.cs) Split a single namespace into multiple c# files We can have nested namespaces also that is namespaces within other namespaces. The.NET base class libraries do so in numerous places to provide an even deeper level of type organization. 5 a) Explain the following with respect to compilation of the C# program in command prompt 10 i) Referencing external assemblies ii) Compiling multiple source files iii) Response files iv) Generating bug reports Answers: - i) The process of referencing external assemblies, let's take an example source code i.e. TestApp application to display a Windows Forms message box. The reference to the System.Windows.Forms namespace is done via the C# "using" directive. When we explicitly list the namespaces used within a given *.cs file, we avoid the need to make use of fully qualified names. In addition to using the "using" keyword, you must also inform csc.exe which assembly contains the referenced namespace. Given that we have made use of the System.Windows.FormsMessageBox class, then we must specify the System.Windows.Forms.dll assembly using the /reference flag. ii) It is permissible to have all the codes in the same file but most projects preferred multiple *.cs files to keep the code base a bit more flexible. To illustrate, assume you have authored an additional class contained in a new file named HelloMsg.cs. BE ISE IV Semester 2

// The HelloMessage Class using System; using System.Windows.Forms; using System.Drawing; class HelloMessage public void Speak() MessageBox.Show("Hello..."); To compile the above code which is using two external assemblies we use the following commands from the command prompt: - The C# compiler allows to make use of the wildcard character (*) to inform csc.exe to include all *.cs files contained in the project directory as part of the current build. When this option is used, you will typically want to specify the name of the output file (/out) as well, to directly control the name of the resulting assembly: csc /r:system.windows.forms.dll /out:testapp.exe *.cs iii) if we build a complex C# application at the command prompt, it would be troublesome as we are required to type in the flags that specify numerous referenced assemblies and *.cs input files. To help lessen typing burden, the C# compiler honors the use of "response files." C# response files contain all the instructions to be used during the compilation of your current build. By convention, these files end in a *.rsp (response) extension and can be used as an alternative to pounding out lines and lines of flags manually at the command prompt. To illustrate, assume that we have created a response file named TestApp.rsp that contains the following arguments /r:system.windows.forms.dll /target:exe /out:testapp.exe *.cs Now, assuming this file is saved in the same directory as the C# source code files to be compiled, we can now build entire application as follows csc @TestApp.rsp Again, the output of the compiler is identical. If the need should arise, we can also specify multiple *.rsp files as input, for example: csc@firstfile.rsp @SecondFile.rsp @ThirdFile.rsp. If we take this approach, we have to be aware that the compiler processes the command options as they are encountered! Therefore, command line arguments in a later *.rsp file can override options in a previous response file. iv) The raw C# compiler provides a helpful flag named /bugreport. As gathered by its name, this flag allows to specify a file that will be populated (by csc.exe) with various statistics regarding your current build, including any errors encountered during the compilation process.

6 a) Write a program to find factorial using default constructor and customized constructor. 10 Answers: - //program to find factorial of a number by implementing default and customized constructor using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace FactExample class Program public static void main(string[] args) Program f1 = new Program(); Program f2 = new Program(5); int n, fact; public Program() n = 1; fact = 1; public Program(int a) n = a; for (int i = 1; i <= n; i++) fact = fact * i; Console.WriteLine("factorial is 0", fact); BE ISE IV Semester 2