






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







int[] arr = { 10, 15, 20, 25, 30 }; foreach(int n in arr) { if(n % 2 == 0) Console.WriteLine(n); }
int[] arr = { 5, 9, 15, 3, 22 }; int max = arr[0]; foreach(int n in arr) { if(n > max) max = n; } Console.WriteLine(max);
int[] arr = { - 1, 5, 8, - 3, 10 }; int count = 0; foreach(int n in arr) { if(n > 0) count++; } Console.WriteLine(count);
int[] arr = {1,2,3,4,5};
Array.Reverse(arr); foreach(int n in arr) Console.WriteLine(n);
int[] arr = {10,20,30,40}; int search = 30; if(arr.Contains(search)) Console.WriteLine("Found"); else Console.WriteLine("Not Found");
List names = new List();
List names = new List(); names.Add("Ali"); names.Add("Ahmed"); names.Add("Sara"); foreach(string name in names) Console.WriteLine(name);
names.Remove("Ahmed");
Console.WriteLine(names.Count);
foreach(string name in students.Values) { Console.WriteLine(name); }
foreach(int key in students.Keys) { Console.WriteLine(key); }
students.Remove(2);
using System.Collections; Hashtable ht = new Hashtable();
Hashtable ht = new Hashtable(); ht.Add(1,"Ali"); ht.Add(2,"Ahmed"); ht.Add(3,"Sara"); foreach(DictionaryEntry item in ht) { Console.WriteLine(item.Key + " " + item.Value); }
if(ht.ContainsKey(2)) { Console.WriteLine(ht[2]); }
ht.Remove(2);
Console.WriteLine(ht.Count);
ht.Clear();
Method Address โ Delegate โ Call Method
delegate void MyDelegate();
using System; delegate void MyDelegate(); class Program { static void Hello() { Console.WriteLine("Hello"); } static void Main() {
Action print = name => Console.WriteLine(name); print("Ali");
Ali
Func add = (a,b) => a+b; Console.WriteLine(add(10,20));
Func length = s => s.Length; Console.WriteLine(length("Ahmed"));
Predicate isEven = x => x % 2 == 0;
Console.WriteLine(isEven(10));
True
parameter => expression
x => x*x
int Square(int x) { return x*x; }
Func square = x => x*x; Console.WriteLine(square(5));
Action greet = name => Console.WriteLine("Hello " + name); greet("Ali");
RollNo:101, Name:"Ahmed", Marks: ); Console.WriteLine(student.RollNo); Console.WriteLine(student.Name); Console.WriteLine(student.Marks);
int[] List
Difference between Tuple and Class