Showing posts with label c sharp variable. Show all posts
Showing posts with label c sharp variable. Show all posts

Sunday, 22 August 2010

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());
}
}

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);

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);
}
}

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 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);
}
}

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());

}

}