P. 1
Mc 0081 Solve

Mc 0081 Solve

|Views: 25|Likes:
Published by Avijit Roy

More info:

Published by: Avijit Roy on May 18, 2013
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less





1. Describe the following with respect to creating Web Forms in .Net environment: a. Web Form Life Cycle b.

Creating a Web Form Write programs with corresponding output screens to demonstrate the above concepts. a) WEB FORM LIFE CYCLE Every request for a page made from a web server causes a chain of events at the server. These events, from beginning to end, constitute the life cycle of the page and all its components. The life cycle begins with a request for the page, which causes the server to load it. When the request is complete, the page is unloaded. From one end of the life cycle to the other, the goal is to render appropriate HTML output back to the requesting browser. The life cycle of a page is marked by the following events, each of which you can handle yourself or leave to default handling by the ASP.NET server: • Initialize: Initialize is the first phase in the life cycle for any page or control. It is here that any settings needed for the duration of the incoming request are initialized. • Load View State: The View State property of the control is populated. The View State information comes from a hidden variable on the control, used to persist the state across round trips to the server. The input string from this hidden variable is parsed by the page framework, and the View State property is set. This can be modified via the LoadViewState ( ) method: This allows ASP.NET to manage the state of your control across page loads. So that each control is not reset to its default state each time the page is posted. • Process Postback Data: During this phase, the data sent to the server in the posting is processed. If any of this data results in a requirement to update the View State, that update is performed via the LoadPostData ( ) method. • Load: CreateChildControls ( ) is called, if necessary, to create and initialize server controls in the control tree. State is restored, and the form controls show client-side data. You can modify the load phase by handling the Load event with the OnLoad method. • Send Postback Change Modifications: If there are any state changes between the current state and the previous state, change events are raised via the RaisePostDataChangedEvent ( ) method. • Handle Postback Events: The client-side event that caused the postback is handled. • PreRender: This is the phase just before the output is rendered to the browser. It is essentially your last chance to modify the output prior to rendering using the OnPreRender ( ) method. • Save State: Near the beginning of the life cycle, the persisted view state was loaded from the hidden variable. Now it is saved back to the hidden variable, persisting as a string object that will complete the round trip to the client. You can override this using the SaveViewState () method. • Render: This is where the output to be sent back to the client browser is generated. You can override it using the Render method. CreateChildControls ( ) is called, if necessary, to create and initialize server controls in the control tree. • Dispose: This is the last phase of the life cycle. It gives you an opportunity to do any final cleanup and release references to any expensive resources, such as database connections. You can modify it using the Dispose ( ) method. • b) CREATING A WEB FORM To create the simple Web Form that will be used in the above example, go to the option start up Visual Studio .NET and open a New Project named ProgrammingCSharpWeb. Select the Visual C# Projects folder (because C# is your language of choice), select ASP.NET Web Application as the project type, and type in its name, ProgrammingCSharpWeb. Visual Studio places nearly all the files it creates for the project in a folder within your local machine's default web site – for example, c:\Inetpub\wwwroot\ProgrammingCSharpWeb. The solution files and other Visual Studio-specific files are stored in <drive>\Documents and Settings\<user name>\My Documents\Visual Studio Projects (where <drive>and <user name>are specific to your machine). When the application is created, Visual Studio places a number of files in your project. The Web Form itself is stored in a file named WebForm1.aspx. This file will contain only HTML. A second, equally important file, WebForm1.aspx.cs, stores the C# associated with your form; this is the code-behind file. The code-behind file does not appear in the Solution Explorer. To see the code behind (.cs) file, you must place the cursor within Visual Studio .NET, right-click the form, and choose "View Code" in the pop-up menu. You can now tab back and forth between the forms itself, WebForm1.aspx, and the C# code-behind file, WebForm1.aspx.cs. When viewing the form, WebForm1.aspx, you can choose between Design mode and HTML mode by clicking the tabs at the bottom of the Editor window. Design mode lets you drag controls onto your form; HTML mode allows you to view and edit the HTML code directly. code-behind files: Start by renaming WebForm1.aspx to HelloWeb.aspx. To do this, close WebForm1.aspx,and then right-click its name in the Solution Explorer. Choose Rename and enter the name HelloWeb.aspx. After renaming it, open HelloWeb.aspx and view the code; it is seen that code-behind file has been renamed as well to HelloWeb.aspx.cs.When you create a new Web Form application, Visual Studio .NET will generate a bit of boilerplate code to get you started, as shown below: <%@ Page language="c#" Codebehind="HelloWeb.aspx.cs" AutoEventWireup="false" Inherits="ProgrammingCSharpWeb.WebForm1" %>

the browser and Web server are disconnected.0"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas. as explained later in the section "Cookies and Session State. if you try to store more.<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4. the browser stores all the cookies separately. Most browsers allow only 20 cookies per site. more browsers will accept cookies from your site. when a user visits your site. A site that asks a user to log on might use a cookie to record that the user already logged on so that the user does not have to keep entering credentials. all relating to helping the Web site remember users. Cookies help Web sites store information about visitors. presenting pertinent identification that helps an application know how to proceed.0 Transitional//EN" > <html> <head> <title>WebForm1</title> <meta name="GENERATOR" Content="Microsoft Visual Studio 7. If you define a P3P privacy policy and place it in the root of your Web site. Generally.NET Introduction: Cookies provide a means in Web applications to store user-specific information. For example. an identifier such as a user ID. Many times. Cookie Limitations: • • Most browsers support cookies of up to 4096 bytes. usually 300. you might have to avoid cookies altogether and use a different mechanism to store user-specific information. you can use cookies to store user preferences or other information. Because of this small limit. A cookie therefore acts as a kind of calling card. Browsers also impose limitations on how many cookies your site can store on the user's computer. the Web server on a shopping site keeps track of individual shoppers so the site can manage shopping carts and other user-specific information. of performing state management. For example. cookies are best used to store small amounts of data. Cookies are associated with a Web site. A common method for storing user information is session state. A cookie is a small bit of text that accompanies requests and pages as they go between the Web server and browser. on the number of cookies they will accept from all sites combined. the oldest cookies are discarded. Describe the following with respect to State Management in ASP. cookies are one way of maintaining continuity in a Web application—that is. however. the application can retrieve the information it stored earlier. Session State c. Except for the brief time when they are actually exchanging information. not with a specific page. Cookies in ASP. Some browsers also put an absolute limit.com/intellisense/ie5"> </head> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> </form> </body> </html> Run the page by pressing Ctrl-F5 (or save it and navigate to it in your browser). However.Net: a. When the user visits your Web site another time. Users can set their browser to refuse cookies." • Writing Cookies . so the browser and server will exchange cookie information no matter what page the user requests from your site. a site conducting a poll might use a cookie simply as a Boolean value to indicate whether a user's browser has already participated in voting so that the user cannot vote twice. it's useful for the Web server to recognize users when they request a page. each site might send a cookie to the user's browser as well. Cookies are used for many purposes. For example. or better yet. The cookie contains information the Web application can read whenever the user visits the site. but session state depends on cookies. As the user visits different sites.microsoft. Application State a)COOKIES IN ASP. Each request a user makes to a Web server is treated independently of any other request.NET b. 2.

Response. A session is considered active as long as requests continue made with the same SessionID value. If no SessionID value is supplied.NET worker process. and so on) can be a challenge.NET session-state variables are easily set and retrieved using the Session property. Session Variables: Session variables are stored in a SessionStateItemCollection object that is exposed through the HttpContext: Session property.Cookies ["userName"]. Each cookie must have a unique name so that it can be identified later when reading it from the browser.NET page.NET application. the cookie is created but it is not stored on the user's hard disk. aCookie.AddDays (1). meaning that your Web server treats each HTTP request for a page as an independent request. HTTP is a stateless protocol. you specify a Name and Value. You can access the HttpResponse object as the Response property of your Page class. building Web applications that need to maintain some cross-request state information (applications that implement shopping carts. ASP. the cookie is discarded. Instead.NET page for the first and last name of a user. Any cookies that you want to send to the browser must be added to this collection. you can also configure the application to store SessionID values in the URL for a "cookieless" session. store session information using a stand-alone service so that session information is preserved if the ASP.NET Framework type.NET applications. Because cookies are stored by name. The collection of session variables is indexed by the name of the variable or by an integer index. the session is considered expired. Session Events: . by default. in a SQL Server so that session information is available to multiple Web servers in a Web farm (and also persists if the ASP. Session Modes:ASP. Response.NET application by default. in a SQL Server database. Cookies are sent to the browser via the HttpResponse object that exposes a collection called cookies. The following example shows the method using C# code to write cookies: Response.Expires = DateTime. In an ASP. The following example shows how to create session variables in an ASP.NET stores session information in the memory space of the ASP.NET application is restarted. you can set the session mode to Off.The browser is responsible for managing cookies on a user system. which stores session variable values as a collection indexed by name. b) SESSION STATEASP. The default behavior is to store session variables in the memory space of the ASP. HttpCookieaCookie = new HttpCookie ("lastVisit"). However.Cookies.Now.Now.Now. and provides the ability to persist variable values for the duration of that session. or in a custom data store. or in a custom data source.NET pages that make up a Web application.NET application is restarted). As a result.Cookies ["userName"]. ASP. Each option is identified as a session-state Mode type. the current session variables are exposed through the Session property of the Page object. ASP. you can also specify that session state should be stored in a separate process. If you do not set the cookie's expiration. We can optionally. ASP. When session state is enabled for an ASP. Session variables can be any valid . If the time between requests for a particular session exceeds the specified time-out value in minutes.Expires = DateTime.to be ASP. Session Identifiers:Sessions are identified by a unique identifier that can be read by using the SessionID property. SessionID values are stored in a cookie. However.Add (aCookie). and set them to values retrieved from TextBox controls.AddDays (1). You can add cookies to the Cookies collection in a number of ways. If you do not want session state enabled for your application. Session variables are created by referring to the session variable by name. aCookie. When creating a cookie.NET starts a new session and the SessionID value for that session is sent to the browser with the response. data scrolling.Value = "patrick". When the user closes the browser. You do not have to declare a session variable or explicitly add it to the collection.NET session state is enabled by default for all ASP.Value = DateTime.NET also provides several other options for persisting data within an application besides session state. Requests made with an expired SessionID value result in a new session. ASP. the cookie is maintained as part of the user's session information. naming two cookies the same will cause one to be overwritten. By default.NET session state identifies requests received from the same browser during a limited period of time as a session. each request for a page in the application is examined for a SessionID value sent from the browser.NET session state enables you to store and retrieve values for a user as the user navigates the different ASP.ToString (). the server retains no knowledge of variable values used during previous requests.NET session state supports several storage options for session variables.

you do so in a thread-safe manner by including built-in synchronization support.NET provides two events that help you manage user sessions. Supporting values that are based on the session Mode setting.NET application. such as a database. If your application runs in multi-processor or multi-server environments.Net: a. c)APPLICATION STATE Application state is a data repository available to all classes in an ASP. we can add objects to the StaticObjects collection via an <object runat="server"> declaration in your Web application's Global. Application state defined in this way can then be accessed from code anywhere in your application.NET application. which is specific to a single user session. which is the default mode. It sets the Timeout value to 30 minutes. The sessionStateelement enables you to specify the following options: • The mode in which the session will store data.Integrated Security=SSPI.asax file. <sessionState mode="SQLServer" cookieless="true” regenerateExpiredSessionId="true " timeout="30" SqlConnectionString="Data Source=MySqlServer. causing the server to page memory to disk. application state is very fast compared to saving data to disk or a database. Therefore.config file is changed. Implementing a Web Service Client . • • • The way in which session identifier values are sent between the client and the server.web configuration section. Application can be used in two ways: • We can add. The HttpApplicationState class can be accessed at any time during the life of an application.NET actively manages the cache and will remove items when memory becomes scarce. You can also configure session state by using the EnableSessionState value in the @ Page directive. You can use the Lock and UnLock methods to ensure data integrity by locking the data for writing by only one source at a time. For example. Application state is stored in memory on the server and is faster than storing and retrieving information in a database. as in a Web garden. Application State Considerations: When using application state. This class exposes a key-value dictionary of objects. or among multiple worker processes serving the same application on the same server. storing large blocks of data in application state can fill up server memory. it is important to ensure that when you update application state data. Using Application State: Application state is stored in an instance of the HttpApplicationState class. for data that must preserve fidelity across the application. it is lost whenever the application is stopped or restarted. consider using a more scalable option. Unlike session state. • Volatility: As the application state is stored in server memory. • Scalability: Application state is not shared among multiple servers serving the same application. application state is a useful place to store small amounts of often-used data that does not change from one user to another. The HttpApplicationState class is most often accessed through the Application property of the HttpContext class. if the Web. the application is restarted and all application state is lost unless application state values have been written to a non-volatile storage medium such as a database. Session events are specified in the Global.NET cache also stores data in memory and is therefore very fast. application state applies to all users and all sessions. however. The HttpApplicationState instance is created the first time a user accesses any URL resource in an application. As an alternative to using application state.NET cache mechanism for storing large amounts of application data. Writing and Testing a Web Service b.ASP. and specifies that session identifiers are stored in the URL. ASP. The following example shows a sessionState element that configures an application for SQLServer session mode. and the Session_OnEnd event is raised when a session is abandoned or expires.asax file for an ASP. The ASP. which means that application state data can be accessed simultaneously by many threads. • Alternatively. The Session_OnStart event is raised when a new session starts. The session Timeout value. you can use the ASP. However. The Session_OnEnd event is not supported if the session Mode property is set to a value other than InProc. or remove values from the Contents collection directly through code." stateNetworkTimeout="30"/> We can disable session state for an application by setting the session-state mode to off. Configuring Session State Session state is configured by using the sessionState element of the system. 3. access. as in a Web farm. you must be aware of the following important considerations: • Resources: Because it is stored in memory. • Concurrency: Application state is free-threaded. Therefore. Your application therefore cannot rely on application state containing the same data for application state across different servers or processes. Describe the following with respect to Web Services in .

It’s easy to write Web services. At a minimum.NET Framework SDK (and that is integrated into Visual Studio .NET displays a page that you can use to test the Add method (Figure 8.NET HTTP handler) in Machine. Web service classes can be attributed with optional WebService attributes. The name and description in the ASMX file’s WebService attribute appear at the top of the page.NET Framework class library (FCL) and a codegenerator named Wsdl.7).a) WRITING AND TESTING A WEB SERVICE b) Writing a Web Service: The ASMX file shown in Figure below. If you put Calc. Calc. near the top of the page.NET (specifically. You can build helper methods into a Web service – methods that are used internally by Web methods but that are not exposed as Web methods themselves – by omitting the attribute. to an ASP. ASP.asmx in his or her browser. the Web service’s local URL is http://localhost/calc. Copy Calc. Click ―Add. The proxy insulates you from the low-level details of the Web service and of the protocols that it uses. c) IMPLEMENTING A WEB SERVICE CLIENTS: Web service clients – that is. The one in this example assigns the Web service a name and a description that show up in the HTML page generated when a user calls up Calc.asmx in wwwroot. Writing Web service clients is even easier.asmx. The methods in the proxy class mirror the Web methods in the Web service. The WebService attribute also supports a Namespace parameter that can be used to change the name of the XML namespace that scopes the Web service’s members. The Wsdl.NET Framework: • • • Web services are implemented in ASMX files.asmxin the browser’s address bar.asmx. and ASP. They also let you explore a Web service built with the . the proxy packages up the input parameters and invokes the Web method using the protocol encapsulated in the proxy (typically SOAP). The XML returned by the Web method appears in a separate browser window The forms that ASP.exe utility that comes with the . applications that use.net/terraservice. A Web service proxy is an object that provides a local representation of a remote Web service. It even generates an HTML form that you can use to call the Add method with your choice of inputs. You’ll learn more about Description and other WebMethod parameters in the section entitled ―The WebMethod AttributeTesting a Web Service: • For testing an ASMX Web service. The WebMethod attributes in Figure 8. the directive must contain a Class attribute identifying the class that makes up the Web service. .asmx by generating an HTML page that describes the Web service.NET knows the method name and signature because it reads them from the metadata in the DLL it compiled from Calc.NET responded to the HTTP request for Calc. type the following URL into your browser’s address bar: http://terraservice.asmx to wwwroot and type http://localhost/calc.exe. For kicks.NET generates on the fly from ASMX files enable you to test the Web services that you write without writing special clients to test them with. ASP. Web Service Proxies: The key concept to grasp when writing Web service clients is that of the Web service proxy.asmx That’s the URL of the Microsoft TerraService. A proxy is instantiated in the client’s own application domain. ASMX is a special file name extension registered to ASP. It implements two Web methods: Add and Subtract. If you have a WSDL contract describing a Web service (or the URL of a DISCO file that points to a WSDL contract). complete with the descriptions spelled out in the WebMethod attributes. an ultra-cool Web service that provides a programmatic interface to a massive database of geographic data known as the Microsoft TerraServer.config. Web methods are declared by tagging public methods in the Web service class with WebMethod attributes. ASMX files begin with @ WebService directives. call it in the browser. but calls to the proxy flow through the proxy and out to the Web service that the proxy represents.NET) generates Web service proxy classes from WSDL contracts. User will be greeted as shown in the figure.asmx demonstrates several important principles of Web service programming using the . If the Web service exposes Web methods named Add and Subtract. thanks to some high-level support lent by the .5 also assign descriptive text to their Web methods. the Web service proxy also contains methods named Add and Subtract.NET Framework simply by pointing your browser to it. Web methods. Underneath is a list of Web methods that the service exposes. Both take two integers as input and return an integer as well. When you call one of these methods. Deploying the Web service is as simple as copying it to a directory on your Web server that is URLaddressable. or consume. Type 2 and 2 into the ―a‖ and ―b‖ boxes and click Invoke. It even parses the XML that comes back and makes the result available as managed types.

asmx".cs and enter the code in Figure. } If the Web service moves.com/calc.cs.com/calc.com/calc. you can use Wsdl.asmx produces the following class constructor: publicCalculatorWebService() { stringurlSetting = System. If you installed Calc.Simple Web Service Client:To write a client.asmx" /> </appSettings> </configuration> . you’ll have to modify the CS file and regenerate the proxy.exe to create a proxy class for Calc.cs "Calculator Web Service.cs" Run CalcClient.asmx".WriteLine ("2 + 2 = " + sum).asmx.asmx in wwwroot.Url = urlSetting. } } Avoiding Hard-Coded Service URLs: Look through a CS file generated by Wsdl. CalcClient.exe.wintellect.cs using System.wintellect. and you’ll see the Web service proxy class as well as the methods that wrap the Web service’s Web methods.wintellect.Configuration. The resulting output proves beyond the shadow of a doubt that Calc.config file. classMyApp { public static void Main () { CalculatorWebServicecalc = new CalculatorWebService (). } } Now you can assign a value to ―CalcUrl‖ in the appSettings section of a local Web.exe responds by creating a file named Calculator Web Service.asmx Wsdl. 2). the proper command is wsdl http://localhost/calc. You’ll also see that the Web service’s URL is hardcoded into the CS file in the proxy’s class constructor.exe instantiates a Web service proxy and calls the service’s Add method. The command wsdl /urlkey:CalcUrl http://www.AppSettings["CalcUrl"]. Eg: publicCalculatorWebService() { this. To avoid having to update code when a Web service’s URL changes. } else { this.ConfigurationSettings. if ((urlSetting != null)) { this.wintellect. like so: <configuration> <appSettings> <add key="CalcUrl" value="http://www.asmx is smart enough to add 2 and 2 CalcClient. • Create a new text file named CalcClient. • • Compile the CS files into a console application with the following command: cscCalcClient.exe. following are the steps: • Use Wsdl. int sum = calc.exe’s /appsettingurlkey (abbreviated /urlkey) switch.com/calc.Url = "http://www.Add (2.Url = "http://www. Console.

• • • For enhanced security. This isolates the test version of the application. to a set of worker processes) that service a group of applications. if you want to configure an application to run with its own unique set of properties. and ensure that your applications remain available even when a worker process serving an application pool is recycled because of a faulty application.0 is available only when running in worker process isolation mode.NET Framework version 1.NET APPLICATIONS Deploying ASP. you can make your server more efficient and reliable.1 of the .NET applications on a newly installed Web server requires no understanding of earlier versions of IIS or the .0 (IIS 6.0 metabase properties. process boundaries separate each worker process from other worker processes so that when an application is routed to one application pool. Deploying ASP.config and Web. In an application pool. reliable.0) b.NET Framework. If there is a test version of an application on the same server with the production version of the application. Version 1. except for the <processModel>section of the Machine.0.0. By creating new application pools and assigning Web sites and applications to them.NET Framework is installed with Windows Server 2003.1 with the operating system installation. in the case of a Web garden. separate the two versions into different application pools. Use an account with the least user rights possible. When IIS 6. you can make your server more efficient.config. Configuring Application Pools in IIS 6.0): This feature of IIS 6. As a design consideration.If another application fails because of the volume of requests that it receives.config file.config files are configured the same way in IIS 6.NET applications on a newly installed server running Internet Information Services (IIS) 6. An application pool is a configuration that links one or more applications to a set of one or more worker processes.0 in worker process isolation mode. an application in one application pool is not affected by problems caused by applications in other application pools. Most ASP. even when the worker process serving the new application pool has problems.NET Framework.0 : The process for deploying new ASP.NET Applications a) CREATING APPLICATION POOLS(IIS 6. Creating Application Pools (IIS 6. No code changes are required 4. such as Network Service in the IIS_WPG group. By using an application pool.0) Microsoft® Windows® Server 2003 includes support for ASP.NET Applications in IIS 6.NET applications and the Microsoft . . you can isolate different Web applications or Web sites in pools.0 (IIS 6.If the URL changes. some of the attributes in the <processModel>section of the Machine.config file are now in equivalent IIS 6. create a unique application pool for that applicationDEPLOYING ASP. Because applications in an application pool are separated from other applications by worker process boundaries. The URLs that you assign to an application pool can be for an application.Net: a.0)When we run IIS 6. configure a unique user account (process identity) for each application pool. Deployment Process using IIS 6. By creating new application pools and assigning Web sites and applications to them. a Web site. applications in other application pools do not affect that application. or a virtual directory. which are called Application Pools. Describe the following with respect to Web site deployment in ASP. and secure. you can set the application pools worker process to recycle when the application exceeds a specified number of requests. a Web directory.NET configuration sections in the Machine.0 is configured to run in worker process isolation mode. All the ASP. Guidelines for Creating Application Pools: To isolate Web applications on a Web site from Web applications on other sites running on the same computer. create an individual application pool for each Web site.1 of the . we can assign specific configuration settings to a worker process (or. This chapter describes how to deploy ASP. An application pool is a group of URLs that are routed to one or more worker processes that share the same configuration. you can update the proxy simply by editing Web.NET applications run without modification on version 1. as well as making your other applications always available.

Depending on the method you select.3. class MainClass { static void Main(string[] args) { int a. you must configure IIS 6. Basic arithmetic operations b. e = d / 2.NET applications need to retain session state.WriteLine(b). f = e % 2.f. Console. if your ASP.d. c = b .b. b = a + 6. you might need to configure the ASP.In addition.0 to use the appropriate ASP. d = c * 2. a = 1. Console. Console.WriteLine(f).c. a) BASIC ARITHMETIC OPERATION: using System.WriteLine(e). Finding greatest of n numbers Write separate programs for each of the above points. 5. Write a program in C# language to perform the following operations: a.WriteLine(c).NET state service or Microsoft SQL Server™ to act as the repository for centralized state storage.e.NET application sessionstate method. } } b) FINDING GREATER OF N NUMBERS public static void FindLargestAndSmallest() { . Console.WriteLine(d). Console.

properties. see Static Classes and Static ClassMembers (C# Programming Guide). Class Inheritance public class Manager : Employee { // Employee fields. a fundamental characteristic of object-oriented programming. If the class is declared as static. then only one copy exists in memory and client code can onlyaccess it through the class itself.. Declaring classes public class Customer { //Fields. //we will now use TryParse to get the numeric value entered isNum = Int32. methods and events. out arraySize). //read in the value string sizeString = Console. If the class is notdeclared as static. methods and events go here.. int[] numArray = new int[50] //ask the user for the size of their array Console. properties. Thevariable remains in memory until all references to it go out of scope. } Creating object Customer object1 = new Customer(). methods and events are inherited // new Manager fields. client code can use it by creating objects or instances which are assigned to a variable.TryParse(sizeString. Unlike structs. classes support inheritance.int arraySize.ReadLine(). methods and events go here. Describe the steps involved in creating classes and objects with the help of a program in C#. } // Method . } EXAMPLE public class Person { // Field public string name. not an instance variable. int largestNum. It defines the data and behavior of a type. // Constructor Public Person () { name = "unknown". For more information.. A class is a construct that enables you to create your own custom types by grouping together variables of othertypes..WriteLine("Enter the size of Array"). //now we will determine if the value is numeric if (isNum) 6. properties. bool isNum. At that time. the CLR marks it as eligible forgarbage collection. A class is like a blueprint.

WriteLine(person.WriteLine("Press any key to exit. } } /* Output:unknownJohn Smith*/ . // Keep the console window 3 Console. person. Console. } } classTestPerson{static void Main() { Person person = new Person().public void SetName(string newName) { name = newName.name).").SetName("John Smith"). Console.name).ReadKey(). Console.WriteLine(person.

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->