Skip to main content

Posts

Showing posts from September, 2013

Declaring a single dimension Array in C sharp

Thinking of using a Single Dimension Array in C-sharp . Following is the code to create or use Single Dimension Array in C-sharp. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SingleDimensionArray { class Program { static void Main(string[] args) { string[] name = new string[2]; int[] sub1 = new int[2]; int[] sub2 = new int[2]; int[] total=new int[2]; for (int i=0;i<=1;i++) { Console.WriteLine("Enter the " + (i + 1) + " student name"); name[i]=Console.ReadLine(); Console.WriteLine("Enter the marks of first subject"); sub1[i] = int.Parse(Console.ReadLine()); Console.WriteLine("Enter the marks of second subject"); sub2[i] = int.Parse(Console.ReadLine()); total[i]=sub1[i]+sub2[i]; } for (int i = 0; i <= 1; i++) { Console.WriteLine("The student name is " + name[i] + " and his total mar

Creating an Enumeration in C Sharp

Thinking of using a Enumeration in C-sharp . Following is the code to create or use enumeration in C-sharp. Enumeration is created using the keyword enum using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CreatingEnumeration {     public enum Color { Red=1, Green, Yellow }     class Program     {         static void Main(string[] args)         {             Console.WriteLine("Please select 1 for Red, 2 for Green, and 3 for Yellow");             string str = Console.ReadLine();             int colInt = Int32.Parse(str);             Color col = (Color)colInt;             switch (col)             {                 case Color.Red:                     Console.WriteLine("The selected color is Red");                     break;                 case Color.Green:                     Console.WriteLine("The selected color is Green");                     break;                 case Color.Yellow