C# is a modern, general-purpose, object-oriented programming language
developed by Microsoft and approved by European Computer Manufacturers
Association (ECMA) and International Standards Organization (ISO).
পৃষ্ঠাসমূহ
Showing posts with label C# Basic Tutorial. Show all posts
Showing posts with label C# Basic Tutorial. Show all posts
Monday, January 30, 2017
C Environment
Try it Option Online
We have set up the C# Programming environment online, so that you can compile and execute all the available examples online. It gives you confidence in what you are reading and enables you to verify the programs with different options. Feel free to modify any example and execute it online.
C Program Structure
Before we study basic building blocks of the C# programming language,
let us look at a bare minimum C# program structure so that we can take
it as a reference in upcoming chapters.
C Basic Syntax
C# is an object-oriented programming language. In Object-Oriented
Programming methodology, a program consists of various objects that
interact with each other by means of actions. The actions that an object
may take are called methods. Objects of the same kind are said to have
the same type or, are said to be in the same class.
C# - Data Types
The variables in C#, are categorized into the following types:
- Value types
- Reference types
- Pointer types
C# - Type Conversion
Type conversion is converting one type of data to another type. It is
also known as Type Casting. In C#, type casting has two forms:
C# - Variables
A variable is nothing but a name given to a storage area that our
programs can manipulate. Each variable in C# has a specific type, which
determines the size and layout of the variable's memory the range of
values that can be stored within that memory and the set of operations
that can be applied to the variable.
C# - Constants and Literals
The constants refer to fixed values that the program may not alter
during its execution. These fixed values are also called literals.
Constants can be of any of the basic data types like an integer
constant, a floating constant, a character constant, or a string
literal. There are also enumeration constants as well.
C# - Operators
An operator is a symbol that tells the compiler to perform specific
mathematical or logical manipulations. C# has rich set of built-in
operators and provides the following type of operators:
C# - Decision Making
Decision making structures requires the programmer to specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.
Following is the general form of a typical decision making structure found in most of the programming languages:
Following is the general form of a typical decision making structure found in most of the programming languages:
C# - Loops
There may be a situation, when you need to execute a block of code several number of times. In general, the statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on.
C# - Encapsulation
Encapsulation is defined 'as the process of enclosing one or more items within a physical or logical package'. Encapsulation, in object oriented programming methodology, prevents access to implementation details.
C# - Methods
A method is a group of statements that together perform a task. Every
C# program has at least one class with a method named Main.
To use a method, you need to:
To use a method, you need to:
- Define the method
- Call the method
C# - Nullables
C# provides a special data types, the nullable types, to which you can assign normal range of values as well as null values.
For example, you can store any value from -2,147,483,648 to 2,147,483,647 or null in a Nullable<Int32> variable. Similarly, you can assign true, false, or null in a Nullable<bool> variable. Syntax for declaring a nullable type is as follows:
For example, you can store any value from -2,147,483,648 to 2,147,483,647 or null in a Nullable<Int32> variable. Similarly, you can assign true, false, or null in a Nullable<bool> variable. Syntax for declaring a nullable type is as follows:
< data_type> ? <variable_name> = null;The following example demonstrates use of nullable data types:
using System; namespace CalculatorApplication { class NullablesAtShow { static void Main(string[] args) { int? num1 = null; int? num2 = 45; double? num3 = new double?(); double? num4 = 3.14157; bool? boolval = new bool?(); // display the values Console.WriteLine("Nullables at Show: {0}, {1}, {2}, {3}", num1, num2, num3, num4); Console.WriteLine("A Nullable boolean value: {0}", boolval); Console.ReadLine(); } } }When the above code is compiled and executed, it produces the following result:
Nullables at Show: , 45, , 3.14157 A Nullable boolean value:
The Null Coalescing Operator (??)
The null coalescing operator is used with the nullable value types and reference types. It is used for converting an operand to the type of another nullable (or not) value type operand, where an implicit conversion is possible.Sunday, January 29, 2017
C# - Arrays
An array stores a fixed-size sequential collection of elements of the
same type. An array is used to store a collection of data, but it is
often more useful to think of an array as a collection of variables of
the same type stored at contiguous memory locations.
C# - Strings
In C#, you can use strings as array of characters, However, more common practice is to use the string keyword to declare a string variable. The string keyword is an alias for the System.String class.
C# - Structures
In C#, a structure is a value type data type. It helps you to make a
single variable hold related data of various data types. The struct keyword is used for creating a structure.
Structures are used to represent a record. Suppose you want to keep track of your books in a library. You might want to track the following attributes about each book:
Structures are used to represent a record. Suppose you want to keep track of your books in a library. You might want to track the following attributes about each book:
C# - Classes
When you define a class, you define a blueprint for a data type. This
does not actually define any data, but it does define what the class
name means. That is, what an object of the class consists of and what
operations can be performed on that object. Objects are instances of a
class. The methods and variables that constitute a class are called
members of the class.
C# - Inheritance
One of the most important concepts in object-oriented programming is
inheritance. Inheritance allows us to define a class in terms of another
class, which makes it easier to create and maintain an application.
This also provides an opportunity to reuse the code functionality and
speeds up implementation time.
C# - Polymorphism
The word polymorphism means having many forms. In
object-oriented programming paradigm, polymorphism is often expressed as
'one interface, multiple functions'.
Polymorphism can be static or dynamic. In static polymorphism, the response to a function is determined at the compile time. In dynamic polymorphism, it is decided at run-time.
Polymorphism can be static or dynamic. In static polymorphism, the response to a function is determined at the compile time. In dynamic polymorphism, it is decided at run-time.
Subscribe to:
Posts (Atom)