C# Lab - Part - B
C# Lab - Part - B
namespace CosoleApplication3
{
abstract class MotorBike
{
}
class Program
{
static void Main(string[] args)
{
// create an object of SportsBike class
SportsBike s1 = new SportsBike();
s1.sports();
Console.ReadLine();
}
}
}
OUTPUT:
namespace single_inheritance
{
}
}
}
OUTPUT:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int mark;
Console.WriteLine("enter the mark");
mark = Convert.ToInt32(Console.ReadLine());
switch (mark / 10)
{
case 10:
case 9:
Console.WriteLine("Grade: A");
break;
case 8:
Console.WriteLine("Grade: B");
break;
case 7:
Console.WriteLine("Grade: C");
break;
case 6:
Console.WriteLine("Grade: D");
break;
case 5:
Console.WriteLine("Grade: E");
break;
default:
Console.WriteLine("Grade: F");
break;
}
Console.ReadLine();
}
}
}
OUTPUT:
Case : 1 Case : 2
namespace lab4
{
public class prgm4
{
public static void Main()
{
int[][] jag = new int[3][];
jag[0] = new int[2];
jag[1] = new int[4];
jag[2] = new int[3];
int[] sum = new int[3];
int result = 0;
int i, j;
for (i = 0; i < 3; i++)
sum[i] = 0;
Console.WriteLine("Enter the size of the array ");
for (i = 0; i < jag.Length; i++)
{
Console.WriteLine("Enter the values off array " + (i + 1) + " jag:");
for (j = 0; j < jag[i].Length; j++)
{
jag[i][j] = int.Parse(Console.ReadLine());
}
}
for (i = 0; i < jag.Length; i++)
{
for (j = 0; j < jag[i].Length; j++)
{
sum[i] = sum[i] + jag[i][j];
}
}
for (i = 0; i < 3; i++)
result = result + sum[i];
Console.WriteLine("The result of individual jags row-wise: ");
for (i = 0; i < 3; i++)
Console.Write(sum[i] + "\t");
Console.WriteLine();
Console.WriteLine("The final sum of all the elements in the jagged array:" + result);
Console.Read();
}
}
}
OUTPUT:
OUTPUT
using System;
delegate int NumberChanger(int n);
namespace example
{
class Delegate
{
static int num = 10;
public static int AddNum(int a)
{
num += a;
return num;
}
OUTPUT
using System;
namespace boxing_unboxing
{
class GFG
{
// Main Method
static public void Main()
{
// boxing
object obj = num;
OUTPUT:
using System;
namespace boxing_unboxing
{
class GFG
{
// Main Method
static public void Main()
{
// boxing
object obj = num;
// unboxing
int i = (int)obj;
// Display result
Console.WriteLine("Value of ob object is : " + obj);
Console.WriteLine("Value of i is : " + i);
Console.ReadLine();
}
}
}
OUTPUT:
namespace Generics
{
class A
{
public virtual void show()
{
Console.WriteLine("Hello: Base Class!");
Console.ReadLine();
}
}
class B : A
{
public override void show()
{
Console.WriteLine("Hello: Derived Class!");
Console.ReadLine();
}
}
class Polymorphism
{
public static void Main()
{
A a1 = new A();
a1.show();
B b1 = new B();
b1.show();
A a2 = new B();
a2.show();
}
}
}
OUTPUT: