Skip to content

Instantly share code, notes, and snippets.

public void PrintAgeAsInt(object age)
{
if (age is int intAge || (age is string stringAge && int.TryParse(stringAge, out intAge)))
{
Console.WriteLine($"Age is {intAge}");
}
}
Dog MarlieTheDog = new Dog(name: "Marlie", age: 7, isFriendly: false);
Cat GarfieldTheCat = new Cat(name: "Garfield", age: 10, isMean: false);
Animal goodAnimal = MarlieTheDog;
switch (goodAnimal)
{
case Dog d when d.IsFriendly:
Console.WriteLine(d.Age);
break;
Dog marlieTheDog = new Dog(name: "Marlie", age: 7, isFriendly: false);
Cat garfieldTheCat = new Cat(name: "Garfield", age: 10, isMean: false);
Animal goodAnimal = marlieTheDog;
switch (goodAnimal)
{
case Dog d when d.IsFriendly: //הצהרה על כלב חדש וביצוע תשאול על מאפייניו
Console.WriteLine(d.Age); //כאן בהכרח יודפס גיל של כלב ידידותי
break;
Dog marlieTheDog = new Dog(name: "Marlie", age: 7, isFriendly: false); // Animal יורש מ
Cat garfieldTheCat = new Cat(name: "Garfield", age: 7, isMean: false); // Animal יורש מ
List<Animal> animals = new List<Animal>() { marlieTheDog, garfieldTheCat }; //יצירת רשימה המכילה חתול וכלב
Animal oldAnimal = animals.Where(animal => animal.Age > 8).FirstOrDefault(); //הצהרה על חיה חדשה - החיה הראשונה ברשימה שגילה גדול מ-8
if (oldAnimal == null) //בדיקה התבצעה השמה לחיה מבוגרת
{
throw new Exception("There aren't any old animals in here"); //Exception במקרה ולא קיימת חיה מבוגרת ברשימה - זריקת
}
Dog marlieTheDog = new Dog(name: "Marlie", age: 7, isFriendly: false);
Cat garfieldTheCat = new Cat(name: "Garfield", age: 7, isMean: false);
List<Animal> animals = new List<Animal>() { marlieTheDog, garfieldTheCat };
Animal oldAnimal = animals.Where(animal => animal.Age > 8).FirstOrDefault() ?? throw new Exception("There aren't any old animals in here");
// אם לא הוכנס ערך, תזרק שגיאה מתאימה
Console.WriteLine($"{oldAnimal.Name} is very old");
public static (string name, int age) GetNameAndAge()
{
string myName = "Tomer";
int myAge = 22;
return (myName, myAge);
}
public static double AverageThreeNumbers(int num1, int num2, int num3)
{
int Sum(int numOne, int numTwo, int numThree) //יצירת פעולה פנימית שמחזירה סכום של שלושה מספרים
{
return numOne + numTwo + numThree;
}
double Division(int numUno, int numDos) //יציאת פעולה פנימית שמחזירה את מנתם של שני מספרים
{
return numUno / numDos;
}
class Dog : Animal
{
private bool isFriendly;
public bool IsFriendly
{
get => this.isFriendly;
set => this.isFriendly = value;
}
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using System;
namespace FirstSelenium
{
[TestFixture]
public class FirstSelenium
public void DoubleTheNumber(int num)
{
Console.WriteLine(num * 2);
}