using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CSharpConsole
{
class Params
{
//method with default value to parameterss
public void AddNums(int x, int y = 50, int z = 25)
{
Console.WriteLine(x + y + z);
}
//method with both input and output parameterss
public void Math1(int a, int b, ref int c, ref int d)
{
c = a + b;
d = a * b;
}
public void Math2(int a, int b, out int c, out int d)
{
c = a + b;
d = a * b;
}
static void Main()
{
Params p = new Params();
// Calling method with default values to parameters
p.AddNums(100);
p.AddNums(100, 100);
p.AddNums(100,z: 100);
p.AddNums(100, 100, 100);
// Calling methods with input and output parameters
int x = 0, y = 0;
p.Math1(100, 50, ref x, ref y);
Console.WriteLine(x + " " + y);
int m, n;
p.Math2(200, 25, out m, out n);
Console.WriteLine(m + " " + n);
Console.ReadLine();
}
}
}
Monday, 11 February 2013
Using Parameters
// Program to print the following pattern
// *****
// *****
// *****
// *****
// *****
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace pattern_4
{
class Program
{
static void Main(string[] args)
{
int i,j, k;
for (i = 1; i <= 5; i++)
{
for (j = 1; j <= i; j++)
{
Console.Write("");
}
for (k = 1; k <= 5; k++)
{
Console.Write("*");
}
Console.WriteLine();
}
Console.ReadKey();
}
}
}
Sunday, 10 February 2013
// Write a program to print the binary format of a number
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
int num;
Console.Write("Enter a Number : ");
num = int.Parse(Console.ReadLine());
int quot;
string rem = "";
while (num >= 1)
{
quot = num / 2;
rem += (num % 2).ToString();
num = quot;
}
// Reversing the value
string bin = "";
for (int i = rem.Length - 1; i >= 0; i--)
{
bin = bin + rem[i];
}
Console.WriteLine("The Binary format for given number is {0}", bin);
Console.Read();
}
}
}
Methods in CSharp
//Using Methods(Example)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CSharpConsole
{
class Method_ex
{
//Non value returning method without parameter
public void Test1()
{
int m = 5;
for (int i = 1; i <= 10; i++)
Console.WriteLine("{0}*{1}={2}", m, i, m * i);
}
// Non value returning method with parameters
public void Test2(int m, int n)
{
for (int i = 1; i <= n; i++)
Console.WriteLine("{0}*{1}={2}", m, i, m * i);
}
//value returning method with out parameters
public string Test3() //Static action
{
string str = ("Hello Leena");
str = str.ToUpper();
return str;
}
//value returning method with parameters
public string Test4(string str)
{
str = str.ToUpper(); //Dynamic Action
return str;
}
static void Main(string[] args)
{
Method_ex m=new Method_ex();
//calling non-value returning methods
m.Test1();
m.Test2(7,20);
//Calling value returning methods
string str=m.Test3();
Console.WriteLine(str);
Console.WriteLine(m.Test4("leena"));
Console.ReadLine();
}
}
}
Friday, 8 February 2013
Watched Videos!!!
Today was a day with practicing some c# programs, some SQL queries and also i saw some videos on C# console application.
I found one very good link on C# windows programing which is given below
Videos of windows programming in C#
I found one very good link on C# windows programing which is given below
Videos of windows programming in C#
Jagged Array
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace jagged_arrray
{
class Program
{
static void Main(string[] args)
{
int[][] arr = new int[4][];
arr[0] = new int[6];
arr[1] = new int[7];
arr[2] = new int[8];
arr[3] = new int[4];
// printing values of jagged array using nested for
for (int i = 0; i < arr.GetLength(0); i++)
{
for (int j = 0; j < arr[i].Length; j++)
Console.Write(arr[i][j] + "");
Console.WriteLine();
}
// assigning values of a jagged array using nested for
for (int i = 0; i < arr.GetLength(0); i++)
{
for (int j = 0; j < arr[i].Length; j++)
arr[i][j] = j + 1;
}
Console.ReadKey();
}
}
}
Two Dimentional Array
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TD_array
{
class td_array
{
static void Main(string[] args)
{
int[,] arr=new int[3,5];
// Can also initialize the values at the time of declaration
/*int[,] arr = {{11,12,13,14,15},
{21,22,23,24,25},
{31,32,33,34,35},
};*/
int x = 0;
//printing values of 2D array using foreach loop
foreach (int i in arr)
Console.Write(i + " ");
Console.WriteLine("\n");
//assigning values to 2D array using nested for
for (int i = 0; i < arr.GetLength(0); i++)
{
for (int j = 0; j < arr.GetLength(1); j++)
{
x = x + 5;
arr[i, j] = x;
}
}
//printing values of 2D array using nested for loop
for (int i = 0; i < arr.GetLength(0); i++)
{
for (int j = 0; j < arr.GetLength(1); j++)
Console.Write(arr[i, j] + " ");
Console.WriteLine();
Console.ReadKey();
}
}
}
}
Subscribe to:
Posts (Atom)