Skip to main content

Posts

Showing posts from August, 2017

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.  C# Methods 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

C# Methods

A strategy is a gathering of articulations that together play out an errand. Each C# program has no less than one class with a strategy named Main.  To utilize a strategy, you have to:  Characterize the strategy  Call the strategy Methods Defining Methods in C# When you characterize a strategy, you essentially proclaim the components of its structure. The linguistic structure for characterizing a strategy in C# is as per the following: <Access Specifier > <Return Type > <Method Name > (Parameter List) { Method Body } Following are the different components of a technique:  Access Specifier : This decides the perceivability of a variable or a technique from another class.  Return type : A technique may restore an esteem. The arrival sort is the information kind of the esteem the technique returns. On the off chance that the strategy is not restoring any esteems, at that point the arrival sort is void.  Method name : Method name

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. Abstraction and encapsulation are related features in object oriented programming. Abstraction allows making relevant information visible and encapsulation enables a programmer to  implement the desired level of abstraction . C# Encapsulation Encapsulation is implemented by using  access specifiers . An  access specifier  defines the scope and visibility of a class member. C# supports the following access specifiers: Public Private Protected Internal Protected internal Public Access Specifier Public access specifier allows a class to expose its member variables and member functions to other functions and objects. Any public member can be accessed from outside the class. The following example illustrates this: using System ; namespace Rectan