//source code how to declare abstract class
using System;
namespace OOPSProj
{
abstract class AbstactParent
{
public void Add1(int x, int y)
{
Console.WriteLine(x + y);
}
public void Sub1(int x, int y)
{
Console.WriteLine(x - y);
}
public abstract void Mul1(int x, int y);
public abstract void Div1(int x, int y);
}
}
Sunday, 22 August 2010
source code for assing values in jagged array
//source code for assing values in jagged array
using System;
class JagDemo
{
static void Main()
{
int[][] arr1 = new int[4][];
arr1[0] = new int[6];
arr1[1] = new int[8];
arr1[2] = new int[7];
arr1[3] = new int[5];
//Assigning values to jagged array
for(int i=0;i {
for(int j=0;j arr[i][j] = j + 1;
}
using System;
class JagDemo
{
static void Main()
{
int[][] arr1 = new int[4][];
arr1[0] = new int[6];
arr1[1] = new int[8];
arr1[2] = new int[7];
arr1[3] = new int[5];
//Assigning values to jagged array
for(int i=0;i
for(int j=0;j
}
Labels:
c# array
source code for assinging and printing values in jagged array
//c# source code for assinging and printing values in jagged array
using System;
class JagDemo
{
static void Main()
{
int[][] arr1 = new int[4][];
arr1[0] = new int[6];
arr1[1] = new int[8];
arr1[2] = new int[7];
arr1[3] = new int[5];
//Assigning values to jagged array
for(int i=0;i{
for(int j=0;jarr[i][j] = j + 1;
}
//Printing values from jagged array
for(int i=0;i{
foreach(int x in arr[i])
Console.Write(x + " ");
Console.WriteLine();
}
}
}
using System;
class JagDemo
{
static void Main()
{
int[][] arr1 = new int[4][];
arr1[0] = new int[6];
arr1[1] = new int[8];
arr1[2] = new int[7];
arr1[3] = new int[5];
//Assigning values to jagged array
for(int i=0;i
for(int j=0;j
}
//Printing values from jagged array
for(int i=0;i
foreach(int x in arr[i])
Console.Write(x + " ");
Console.WriteLine();
}
}
}
Labels:
c# array
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
different type variable
// source code different type variable
using System;
class TypeDemo
{
static void Main()
{
var x1 = 100;
Console.WriteLine(x.GetType());
var s1 = "Hello";
Console.WriteLine(s.GetType());
var f1= 3.14f;
Console.WriteLine(f.GetType());
var b1 = true;
Console.WriteLine(b.GetType());
}
}
using System;
class TypeDemo
{
static void Main()
{
var x1 = 100;
Console.WriteLine(x.GetType());
var s1 = "Hello";
Console.WriteLine(s.GetType());
var f1= 3.14f;
Console.WriteLine(f.GetType());
var b1 = true;
Console.WriteLine(b.GetType());
}
}
Labels:
c sharp variable
Assigning values and Printing values from 2d array
//source code for Assigning values and Printing values from 2d array
using System;
class TDArray
{
static void Main()
{
int[,] arr = new int[4,5];
int a = 5;
//Assigning values to 2d array;
for(int i=0;i{
for(int j=0;j{
arr[i,j] = a;
a += 5;
}
}
//Printing values from 2d array:
for(int i=0;i{
for(int j=0;jConsole.Write(arr[i,j] + " ");
Console.WriteLine();
}
}
}
using System;
class TDArray
{
static void Main()
{
int[,] arr = new int[4,5];
int a = 5;
//Assigning values to 2d array;
for(int i=0;i
for(int j=0;j
arr[i,j] = a;
a += 5;
}
}
//Printing values from 2d array:
for(int i=0;i
for(int j=0;j
Console.WriteLine();
}
}
}
Labels:
c# array
source code forAssigning values to 2d array
//source code forAssigning values to 2d array;
using System;
class TDArray
{ //source code for array
static void Main()
{
int[,] arr = new int[4,5];
int a = 5;
// source code forAssigning values to 2d array;
for(int i=0;i{
for(int j=0;j{
arr[i,j] = a;
a += 5;
}
}
using System;
class TDArray
{ //source code for array
static void Main()
{
int[,] arr = new int[4,5];
int a = 5;
// source code forAssigning values to 2d array;
for(int i=0;i
for(int j=0;j
arr[i,j] = a;
a += 5;
}
}
Labels:
c# array
//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
source code to return a value
//source code to return a value
using System;
namespace MyCsNsp
{
public class CSTest
{
public string CSMethod()
{
return "Hello from CSharp";
}
}
}
using System;
namespace MyCsNsp
{
public class CSTest
{
public string CSMethod()
{
return "Hello from CSharp";
}
}
}
Labels:
c# functions
source code using for each loop and(integer) using command line argument
using System;
class AddParams
{
static void Main(string[] args)
{
int sum = 0;
foreach(string str in args)
sum += int.Parse(str);
Console.WriteLine(sum);
class AddParams
{
static void Main(string[] args)
{
int sum = 0;
foreach(string str in args)
sum += int.Parse(str);
Console.WriteLine(sum);
Labels:
c sharp variable
source code using for each loop and using command line argument
// using for each loop and using command line argument using System;
class AddParams
{
//fuusing command line argument
static void Main(string[] args)
{
int sum = 0;
foreach(string str in args)
sum += int.Parse(str);
Console.WriteLine(sum);
}
}
Labels:
c sharp variable
source code to create table
//source code to create table of a number
using System;
class RetDemo
{
static void Main()
{
//source function code to create table
Console.Write("Enter a numeric value: ");
int x = int.Parse(Console.ReadLine());
if (x < 2)
return;
for(int i=1;i<=10;i++)
Console.WriteLine("{0} * {1} = {2}", x, i, x*i);
}
}
using System;
class RetDemo
{
static void Main()
{
//source function code to create table
Console.Write("Enter a numeric value: ");
int x = int.Parse(Console.ReadLine());
if (x < 2)
return;
for(int i=1;i<=10;i++)
Console.WriteLine("{0} * {1} = {2}", x, i, x*i);
}
}
Labels:
c sharp variable
using integer parsing code and source code for addition
//using integer parsing code and source code for addition
using System;
class VarDemo
{
//adddition source code
static void Main()
{
int x, y, z;
Console.Write("Enter x value: ");
x = int.Parse(Console.ReadLine());
Console.Write("Enter y value: ");
y = int.Parse(Console.ReadLine());
z = x + y;
Console.WriteLine("Sum of " + x + " and " + y + "is: " + z);
}
}
using System;
class VarDemo
{
//adddition source code
static void Main()
{
int x, y, z;
Console.Write("Enter x value: ");
x = int.Parse(Console.ReadLine());
Console.Write("Enter y value: ");
y = int.Parse(Console.ReadLine());
z = x + y;
Console.WriteLine("Sum of " + x + " and " + y + "is: " + z);
}
}
Labels:
c sharp variable
different type of function
//different type of function
using System;
namespace AccessDemo1
{
public class Program
{
//private function
private void Test1()
{
Console.WriteLine("Private Method");
}
//internal function
internal void Test2()
{
Console.WriteLine("Internal Method");
}
//protected function
protected void Test3()
{
Console.WriteLine("Protected Method");
}
//protected internal function
protected internal void Test4()
{
Console.WriteLine("Protected Internal Method");
}
//public function
public void Test5()
{
Console.WriteLine("Public Method");
}
static void Main(string[] args)
{
Program p = new Program();
p.Test1(); p.Test2(); p.Test3();
p.Test4(); p.Test5();
Console.ReadLine();
}
}
}
using System;
namespace AccessDemo1
{
public class Program
{
//private function
private void Test1()
{
Console.WriteLine("Private Method");
}
//internal function
internal void Test2()
{
Console.WriteLine("Internal Method");
}
//protected function
protected void Test3()
{
Console.WriteLine("Protected Method");
}
//protected internal function
protected internal void Test4()
{
Console.WriteLine("Protected Internal Method");
}
//public function
public void Test5()
{
Console.WriteLine("Public Method");
}
static void Main(string[] args)
{
Program p = new Program();
p.Test1(); p.Test2(); p.Test3();
p.Test4(); p.Test5();
Console.ReadLine();
}
}
}
Labels:
c# functions
Sunday, 13 June 2010
Get the type of variable
using System;
class Vars
{
static void Main()
{
var x = 100;
Console.WriteLine(x.GetType());
var s = "Hello";
Console.WriteLine(s.GetType());
var b = true;
Console.WriteLine(b.GetType());
}
}
class Vars
{
static void Main()
{
var x = 100;
Console.WriteLine(x.GetType());
var s = "Hello";
Console.WriteLine(s.GetType());
var b = true;
Console.WriteLine(b.GetType());
}
}
Labels:
c sharp variable
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)