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();
}
}
}
Subscribe to:
Comments (Atom)