Skip to main content

Posts

Showing posts from December, 2019

Object Oriented Programming in C#

Object Oriented Programming in C# Object oriented programming (OOP) is a programming structure where programs are organized around objects instead of action and logic used in the early age of programming, though some still organize their programs around actions and logic. Understanding OOP concepts can help make decisions about how you should design an application and what language to use. Everything in OOP is placed together as self-sustainable or self-contained “objects.” An object is a combination of variables, functions, and data that performs a set of related activities. When the object performs those activities, it defines the object’s behavior. In addition, an object is an instance of a class. C# offers full support for OOP including inheritance, encapsulation, abstraction, and polymorphism. Lets deal with the attributes of OOP one after another. Inheritance Inheritance in OPP, is the ability to receive (“inherit”) the behaviours and states of an other existing cl...

If statement in C#

C# If statement If statement is one of the flow control and conditional statements in C# programming language. Control flows change the execution flow of a programming language. If someone for example, want to execute a particular statements based on some logic, then flow control and conditional statement come up. The if statement is used to evaluate a Boolean expression before executing a set of statements. The statements are run if the expression evaluate to true else it will run another statement. Syntax if(boolean expression) {     //statements to run } Code using system namespace csharpnaijaDemo {    class program    {       static void main(string[] args)       {            int value=10;            if(value <= 10)             {                   Consoile....

Looping in C#

Looping in C# Looping in programming language is a way to execute a statement or a set of statements repeatedly for a number of times depending on the result of condition to be evaluated. The result of the  condition should be true for the statements within the loop body to be executed statements. Loop Category There are mainly two categories of Loop; these are Entry Controlled Loops These types of loop have their conditions tested in the beginning of the loop body. example are While loop and for loops. Exit Controlled Loops These are loops in which conditions are tested at the end of loop body.   do-while  is an example of exit controlled loop. Note:  In Exit Controlled Loops, loop body will be evaluated for at-least one time as the testing condition is present at the end of loop body. Example of entry controlled loops while loop In while loop, t he test condition is given in beginning of loop and all statements are executed till the give...

Palindrome Words in C#

How to determine if given word is palindrome Palindrome is a word that spells same both backward or forward lets have a method the returns true or false based on the status of the word whether palindrome or not public bool IsPalindrome(string words) {      //declare a variable named reverse and set it to empty string     string reverse=string.Empty;     for (var index=words.Length-1,index >=0;index--)    {         reverse +=words[index].ToString();     }     if(reverse == words)       return true;      else          return false;  }  static void Main(string[] args) {    Console.WriteLine("Enter a word");    string words=Console.ReadLine();    var isPolindrome=IsPalindrome(words);    if (isPolindrome)    {        Console.WriteLine("The  ...

Palindrome Number in C#

How to determine if a number is palindrome or not in c# Let us first know what is palindrome   Palindrome is a word, phrase, or sequence that reads the same backwards as forwards, e.g. madam or nurses run,civic,deleveled,level,rotor. from the definition we can now write the algorithm 1. get the number 2. store the number in a temporary variable 3. reverse the number 4. compare the temporary number with the reversed number if same return palindrome or return not palindrome the implementation in C# let use modular programming for this class program{   static void Main(string[] agrs){        int number;        Console.WriteLine("\n >>> To Find a number is Palindrome or not <<<");        Console.Write("\n Enter a numer");        number=Convert.ToInt32(Console.ReadLine());        var isPalindrome = IsPalindrome(number);       ...