Function in c#
Function:
Ex.
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
namespace
ConsoleApp2
{
class Program
{ void display()
{
Console.WriteLine("welcome");
}
static void Main(string[] args)
{
//create object
//classname objname = new
classname();
Program p1 = new Program();
p1.display();
Console.ReadKey();
}
}
}
# function parameters:- all the parameters
are declared inside the function brackets().
Ex. Display(a)
Ex.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Program
{ void display(int a )// receiver parameters
{
Console.WriteLine(a);
Console.WriteLine("welcome");
}
static void Main(string[] args)
{
//create object
//classname objname = new classname();
Program p1 = new Program();
p1.display(20);// sender parameters
Console.ReadKey();
}
}
}
# input concept:-
All types of input fundamentals are declared in MAIN BODY.
Ex of program with the help of user input
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace input
{
class Program
{ //
creating input function
void input(int roll,string name)
{ // printing input function
parameters
Console.WriteLine(roll);
Console.WriteLine(name);
}
static void Main(string[] args)
{// creating variable for input
int roll1;
string name1;
Console.WriteLine("Enter your roll no.");
roll1 = int.Parse(Console.ReadLine());
Console.WriteLine("enter your name");
name1 = Console.ReadLine();
// object creation
Program p1 = new Program();
p1.input(roll1,name1);
Console.ReadKey();
}
}
}
Imp
What is named parameters:
In this type of parameters all parameters
is used to pass all data values with parameter name
Ex. using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace parameters
{
class Program
{
void input(int roll , string name)
{
Console.WriteLine(roll);
Console.WriteLine(name);
}
static void Main(string[] args)
{
Program r1 = new Program();
r1.input(name:"raju",roll:243);
Console.ReadKey();
}
}
}
Task 1 :- convert the named parameters
into userinput.0
Task2:- create students grade system(js
wala)
Into C# function with named parameters.
Comments
Post a Comment