0% found this document useful (0 votes)
29 views12 pages

Lec 3

This is a digital logic desig lectures that you can use for and answers using it loop This is a digital logic desig lectures that you can use for and answers using it loop
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views12 pages

Lec 3

This is a digital logic desig lectures that you can use for and answers using it loop This is a digital logic desig lectures that you can use for and answers using it loop
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

FUNDAMENTALS OF

PROGRAMING
Writeline
Write
Read
Readline
Readkey
Function
String Functions ( substring,len,append,split,
Concat,interpolation,indexof)
FUNDAMENTALS OF
PROGRAMING
The + operator can be used between strings to combine them. This is called concatenation:

string firstName = “Hassan";


string lastName = “Great";
string name = string.Concat(firstName, lastName);
Console.WriteLine(name);
FUNDAMENTALS OF
PROGRAMING
Another option of string concatenation, is string interpolation, which substitutes values of
variables into placeholders in a string. Note that you do not have to worry about spaces, like with
concatenation:

string firstName = “Sindh";


string lastName = “University";
string name = $"My full name is: {firstName} {lastName}";
Console.WriteLine(name);

String interpolation was introduced in C# version 6.


FUNDAMENTALS OF
PROGRAMING
Another useful method is Substring(), which extracts the characters from a string, starting from
the specified character position/index, and returns a new string. This method is often used
together with IndexOf() to get the specific character position:

static void Main()


{
// Full name
string name = “12Solutions";

// Location of the letter D


int charPos = name.IndexOf(“S");

// Get last name


string lastName = name.Substring(charPos);

// Print the result


Console.WriteLine(lastName);
}
FUNDAMENTALS OF
PROGRAMING
A method is a block of code which only runs when it is called.
You can pass data, known as parameters, into a method.

Methods are used to perform certain actions, and they are also known as functions.
Why use methods? To reuse code: define the code once, and use it many times.

static void MyMethod()


{
Console.WriteLine(“worked “);
}

static void Main(string[] args)


{
MyMethod();
}
FUNDAMENTALS OF
PROGRAMING
Syntax of C# Methods
As discussed, c# Methods must be declared either in a class or struct by
specifying the required access level, return type, name of the method, and
any method parameters as shown below.

class class_name
{
...
...
<Access_Specifier> <Return_Type> Method_Name()
{
public void GetUsers() {
}
// Statements to Execute // Statements to Execute
... }
...
}
FUNDAMENTALS OF
PROGRAMING
If you observe the above syntax, we defined the method in a class with various parameters, which
are

Access_Specifier - It is used to define an access level, either public or private, etc., to allow other
classes to access the method. If we didn’t mention any access modifier, then by default, it is
private.

Return_Type - It is used to specify the type of value the method can return. If the method is not
returning any value, then we need to mention void as the return type.

Method_Name - It must be a unique name to identify the method in a class.


Parameters - The method parameters are useful to send or receive data from a method, and these
method parameters are enclosed within parentheses and are separated by commas. If no
parameters are required for a method, we need to define a method with empty parentheses
FUNDAMENTALS OF
PROGRAMING
void calclulater()
{
Console.WriteLine("enter your ist num");
int istnum = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter your 2nd num");
int sectnum = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("what you want");
Console.WriteLine("click 1 for addition,2 for substraction,3 for mutiplication,4 for division");
int choice = Convert.ToInt32(Console.ReadLine());
switch (choice) {
case 1:
int sum = istnum + sectnum;
Console.WriteLine("you choose addition,after addition ans is " + sum);
break;
case 2:
int subt=istnum - sectnum;
Console.WriteLine("you choose sub,after sub ans is " + subt);
break; }}
FUNDAMENTALS OF
PROGRAMING
public void GetUsers() {
// Statements to Execute
}

//2 parameter 1 string,1 int


private void InsertUserDetails(string name, int age) {
// Statements to Execute
}
1 parameter int
protected string GetUserDetails(int userid)
{
// Statements to Execute
}
FUNDAMENTALS OF
PROGRAMING
public void calculation() {
// Statements to Execute
}
FUNDAMENTALS OF
PROGRAMING
Void GetUserDetails()
{
string name, int age
string info = string.Format("Name: {0}, Age: {1}", name, age);
return info;
}
WHAT'S APP NUMBER
WHAT'S APP :92-3193416769
EMAIL:[email protected]

You might also like