C# Control Statements => If Else Statement

| Page Views: 23

C# control statements with a simple if else statement to check negative and positive numbers.


  • Beginner C# tutorial right here.
  • We've used Visual Studio as our IDE.
  • The code is well commented for easier understanding.

Common Questions we answer

With this simple example we explore the following :

  • How to use If-Else statement in C#.
  • How to determine negative and positive numbers.
  • How to loop throgh an array.
  • How to use a ForEach loop.
  • How to write or read from console.

Tools Used

  • IDE : Visual Studio 2013
  • OS : Windows 8.1

Source Code

Here's the source code :  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace If_Stmt
    class Program
        static readonly int[] numbers={2,-8,9,5,-7,3,-4};
        static void Main(string[] args)
            foreach (var num in numbers)
                if (num < 0)
                    Console.WriteLine(num+" is negative");
                    Console.WriteLine(num + " is Positive");




[caption id="" align="alignnone" width="170"]C# If Else statement C# If Else statement[/caption]

How To Run

  • Just copy the project above.
  • Open the Visual Studio.
  • From the Menu bar click on File -> New -> Visual C# -> Console
  • Type the project name.
  • Paste the code in the program.cs file
  • Click Start to run the project



  • Visit our channel for more examples like these.



How do You Feel after reading this?

According to scientists, we humans have 8 primary innate emotions: joy, acceptance, fear, surprise, sadness, disgust, anger, and anticipation. Feel free to tell us how you feel about this article using these emotes or via the comment section. This feedback helps us gauge our progress.

Help me Grow.

I set myself some growth ambitions I desire to achieve by this year's end regarding this website and my youtube channel. Am halfway. Help me reach them by:


What do You Think

Previous Post Next Post