Creating Objects



Programming An object is an instance of a class. You create objects to access member variables and member functions of a class. It also discusses how to write and execute C# programs. Details Declaring Variables Consider a situation where you have to create a program that accepts two numbers from a user and displays the sum of the numbers on the screen. Now, while reading the numbers provided by the user, you need to store these numbers somewhere in the memory so that you can perform the add operation on the numbers. You can store the numbers in the memory by using variables. Data Types in C# C# provides various built-in data types. Built-in data types are predefined data types that can be directly used in a program to declare variables. The following table lists some of the built-in data types in C#.Accepting and Storing Values in Member Variables To understand how to store value in a variable, consider the following code snippet:int Number; Number = Convert.ToInt32 (Console.ReadLine()); In the preceding code snippet, the Console.ReadLine()method is used to accept data from the user and store it in the variable named Number. The Console.ReadLine()method is a method of the Consoleclass, which is a part of the System namespace. Further, the Convert.ToInt32()method converts the data provided by the user to the intdata type. You need to do this conversion because the Console.ReadLine()method, by default, accepts the data in the string format. The Convert()method explicitly informs the compiler to convert one data type to the other. This is known as explicit conversion. In addition to explicit conversion, there are instances when the compiler performs implicit conversions, which are done automatically (without any explicit coding). For example, implicit conversion converts the intdata type to floator floatdata type to int,automatically.

Sent from Windows Mail

Popular posts from this blog

ch11 review silberschatz operating systems concepts essentials 2nd ed