using System;
namespace OOPSProject
{
class Params
{
int x, y; // Class Variables
Params(int x, int y) //Block Variables
{
this.x = x;
this.y = y;
}
void Add()
{
Console.WriteLine(x + y);
}
void Sub()
{
Console.WriteLine(x - y);
}
void Mul()
{
Console.WriteLine(x * y);
}
void Div()
{
Console.WriteLine(x / y);
}
static void Main()
{
Params obj = new Params(100, 50);
obj.Add(); obj.Sub(); obj.Mul(); obj.Div();
Console.ReadLine();
}
}
}
Showing posts with label c sharp program. Show all posts
Showing posts with label c sharp program. Show all posts
Sunday, 22 August 2010
to declare object
//source code to declare object
using System;
namespace OOPSProj
{
class First
{
int x = 100;
static void Main()
{
First f11 = new First();
First f22 = f11;
f11 = null;
Console.WriteLine(f22.x); //Valid
Console.WriteLine(f12.x); //InValid
Console.ReadLine();
}
}
}
using System;
namespace OOPSProj
{
class First
{
int x = 100;
static void Main()
{
First f11 = new First();
First f22 = f11;
f11 = null;
Console.WriteLine(f22.x); //Valid
Console.WriteLine(f12.x); //InValid
Console.ReadLine();
}
}
}
Labels:
c sharp program
source code to import namespace
//source code to import namespace
using System;
class Using1Demo
{
static void Main()
{
Console.WriteLine("Importing a namespace inc#");
}
using System;
class Using1Demo
{
static void Main()
{
Console.WriteLine("Importing a namespace inc#");
}
Labels:
c sharp program
//source code for usin switch statement
//source code for usin switch statement
using System;
class SwitchDemo
{
static void Main()
{
Console.Write("Enter student no.(1-3): ");
int sno = int.Parse(Console.ReadLine());
switch(sno)
{
case 1:
Console.WriteLine("Student 1");
break;
case 2:
Console.WriteLine("Student 2");
break;
case 3:
Console.WriteLine("Student 3");
break;
default:
Console.WriteLine("Wrong student no.");
break;
}
}
}
using System;
class SwitchDemo
{
static void Main()
{
Console.Write("Enter student no.(1-3): ");
int sno = int.Parse(Console.ReadLine());
switch(sno)
{
case 1:
Console.WriteLine("Student 1");
break;
case 2:
Console.WriteLine("Student 2");
break;
case 3:
Console.WriteLine("Student 3");
break;
default:
Console.WriteLine("Wrong student no.");
break;
}
}
}
Labels:
c sharp program
source code for using if in c#
//source code for using if in c#
using System;
class IfDemo
{
static void Main()
{
int x, y;
Console.Write("Enter x value: ");
x = int.Parse(Console.ReadLine());
Console.Write("Enter y value: ");
y = int.Parse(Console.ReadLine());
if (x > y)
Console.WriteLine("x is greater");
else if(x < y)
Console.WriteLine("y is greater");
else
Console.WriteLine("Both are equal");
}
}
using System;
class IfDemo
{
static void Main()
{
int x, y;
Console.Write("Enter x value: ");
x = int.Parse(Console.ReadLine());
Console.Write("Enter y value: ");
y = int.Parse(Console.ReadLine());
if (x > y)
Console.WriteLine("x is greater");
else if(x < y)
Console.WriteLine("y is greater");
else
Console.WriteLine("Both are equal");
}
}
Labels:
c sharp program
source code for using if in c#
//source code for using if in c#
using System;
class IfDemo
{
static void Main()
{
int x, y;
Console.Write("Enter x value: ");
x = int.Parse(Console.ReadLine());
Console.Write("Enter y value: ");
y = int.Parse(Console.ReadLine());
if (x > y)
Console.WriteLine("x is greater");
else if(x < y) Console.WriteLine("y is greater"); else Console.WriteLine("Both are equal"); } }
using System;
class IfDemo
{
static void Main()
{
int x, y;
Console.Write("Enter x value: ");
x = int.Parse(Console.ReadLine());
Console.Write("Enter y value: ");
y = int.Parse(Console.ReadLine());
if (x > y)
Console.WriteLine("x is greater");
else if(x < y) Console.WriteLine("y is greater"); else Console.WriteLine("Both are equal"); } }
Labels:
c sharp program
simple c# programme
//source code for simple porg
class Example
{
static void Main()
{
System.Console.WriteLine("Welcome to C#");
}
}
class Example
{
static void Main()
{
System.Console.WriteLine("Welcome to C#");
}
}
Labels:
c sharp program
Sunday, 13 June 2010
starting program
class Example
{
static void Main()
{
System.Console.WriteLine("First C# Program");
}
}
{
static void Main()
{
System.Console.WriteLine("First C# Program");
}
}
Labels:
c sharp program
Subscribe to:
Posts (Atom)