static void Main(string[] args) { CountIt count = delegate { Console.WriteLine("I am in anonymous method"); }; count(); //////////////////////////////////////////////////////////////// CountIt2 count2 = delegate(int p1) { Console.WriteLine("I am in anonymous method with parameter = " + p1); }; count2(2); CountIt3 count3 = delegate(int x) { Console.WriteLine("I am in anonymous method with parameter = " + x); return(x + x); }; int y = count3(2); Console.WriteLine("Y = " + y); }
public static void tryCapture() { CountIt ct = counter.Counter(); Console.WriteLine(ct(3)); Console.WriteLine(ct(5)); }
static void Main() { int result; // Here, the ending value for the count // is passed to the anonymous method. // A summation of the count is returned. CountIt count = delegate(int end) { int sum = 0; for (int i = 0; i <= end; i++) { Console.WriteLine(i); sum += i; } return(sum); // return a value from an anonymous method }; result = count(3); Console.WriteLine("Summation of 3 is " + result); Console.WriteLine(); result = count(5); Console.WriteLine("Summation of 5 is " + result); }
static void Main(string[] args) { CountIt count = () => Console.WriteLine("I am in Lambda Expression"); count(); MyDel d1 = (int x) => x + x; int y = d1(4); Console.WriteLine("y = " + y); d1 = z => z * z; int k = d1(3); Console.WriteLine(" k = " + k); MyDel2 d2 = (x, h) => { Console.WriteLine("x = " + x + " h= " + h); return(x + h); }; int g = d2(1, 2); Console.WriteLine("g =" + g); }
static void Main(string[] args) { int result; // Здесь конечное значение для подсчета перелается анонимному методу. // А возвращается сумма подсчитанных чисел. CountIt count = delegate(int end) { int sum = 0; for (int i = 0; i <= end; i++) { Console.WriteLine(i); sum += i; } return(sum); // возвратить значение из анонимного метода }; result = count(3); Console.WriteLine("Сумма 3 равна " + result); Console.WriteLine(); result = count(5); Console.WriteLine("Сумма 5 равна " + result); Console.ReadKey(); }
public static void Main() { CountIt count = counter(); int result = count(3); result = count(5); }
public static void Main() { CountIt count = delegate(int end) { Console.WriteLine("end:" + end); }; count(3); count(5); }
public void ShouldIgnoreLetterCaseWords() { var counter = new CountIt(); string result = counter.CountWords("AB Cd"); var expectedResult = "Number of words: 2\r\nab 1\r\ncd 1\r\n\r\nbA\r\ndC"; Assert.AreEqual(expectedResult, result); }
static CountIt counter() { CountIt ctObj = delegate(int end) { Console.WriteLine("end:" + end); return(end); }; return(ctObj); }
public void ShouldSkipNumbersAndDots() { var counter = new CountIt(); string result = counter.CountWords("a b b. 1 2.. 3"); var expectedResult = "Number of words: 3\r\na 1\r\nb 2\r\n\r\na\r\nb"; Assert.AreEqual(expectedResult, result); }
public void ShouldCapitalizeEvenLetters() { var counter = new CountIt(); string result = counter.CountWords("abcd de"); var expectedResult = "Number of words: 2\r\nabcd 1\r\nde 1\r\n\r\ndCbA\r\neD"; Assert.AreEqual(expectedResult, result); }
public void ShouldCountOneAndTwoWords() { var counter = new CountIt(); string result = counter.CountWords("a b b"); var expectedResult = "Number of words: 3\r\na 1\r\nb 2\r\n\r\na\r\nb"; Assert.AreEqual(expectedResult, result); }
public void ShouldCountSingleWords() { var counter = new CountIt(); string result = counter.CountWords("ab bc"); var expectedResult = "Number of words: 2\r\nab 1\r\nbc 1\r\n\r\nbA\r\ncB"; Assert.AreEqual(expectedResult, result); }
public void ShouldSortWords() { var counter = new CountIt(); string result = counter.CountWords("it do"); var expectedResult = "Number of words: 2\r\ndo 1\r\nit 1\r\n\r\noD\r\ntI"; Assert.AreEqual(expectedResult, result); }
public void countItTest() { var c = new CountIt(); Assert.AreEqual(6, c.countIt(8809)); Assert.AreEqual(0, c.countIt(7111)); Assert.AreEqual(0, c.countIt(1234)); Assert.AreEqual(4, c.countIt(6666)); Assert.AreEqual(0, c.countIt(1111)); Assert.AreEqual(5, c.countIt(8096)); Assert.AreEqual(4, c.countIt(90485)); }
static void Main() { CountIt count = delegate { //匿名メソッド、以下のコードブロックを参照するデリゲートが作成される。 for (int i = 0; i <= 5; i++) { Console.Write(i + " "); } }; count(); Console.WriteLine(); }
static void Main(string[] args) { CountIt count = delegate { for (int i = 0; i <= 5; i++) { Console.WriteLine(i); } }; count(); }
public static void Start() { CountIt count = delegate { // This is the block of code passed to the delegate. for (int i = 0; i <= 5; i++) { Console.WriteLine(i); } }; // notice the semicolon count(); }
static void Main() { // Get a counter. CountIt count = Counter(); int result; result = count(2); Console.WriteLine("Summation of 3 is " + result); Console.WriteLine(); result = count(5); Console.WriteLine("Summation of 5 is " + result); }
static void Main(string[] args) { Console.WriteLine("Let's calculate words. Type In text. Characters, dots and numbers Are allowed."); var input = Console.ReadLine(); var countIt = new CountIt(); Console.WriteLine(countIt.CountWords(input)); Console.WriteLine(); Console.WriteLine("Good Bye!"); Console.ReadLine(); }
public static void Main() { CountIt count = delegate(int end) { Console.WriteLine("end:" + end); return(end); }; int result = count(3); Console.WriteLine("Summation of 3 is " + result); result = count(5); Console.WriteLine("Summation of 5 is " + result); }
static void Main(string[] args) { // далее следует код для подсчета чисел,передаваемый делегату в кач-ве анонимного метода CountIt count = delegate { //этот кодовый блок передается делегату for (int i = 0; i <= 5; i++) { Console.WriteLine(i); } }; count(); }
static void Main(string[] args) { //получить результат подсчёта VarCapture varCapture = new VarCapture(); CountIt count = varCapture.Counter(); int result; result = count(3); Console.WriteLine("Сумма 3 равна " + result); Console.WriteLine(); result = count(5); Console.WriteLine("Сумма 5 равна " + result); }
public static void Start() { // Here, the code for counting is passed // as an anonymous method. CountIt count = delegate { // This is the block of code passed to the delegate. for (int i = 0; i <= 5; i++) { Console.WriteLine(i); } }; // notice the semicolon count(); }
static void Main() { // Получить результат подсчета. CountIt count = Counter(); int result; result = count(3); Console.WriteLine("Сумма 3 равна " + result); Console.WriteLine(); result = count(5); Console.WriteLine("Сумма 5 равна " + result); }
static void Main(string[] args) { // Console.WriteLine("Hello World!"); CountIt count = Counter(); int result; result = count(3); Console.WriteLine("Summation of 3 is:" + result); Console.WriteLine(); result = count(5); Console.WriteLine("Summation of 5 is:" + result); }
static void Main() { // Здесь конечное значение для подсчета передается анонимному методу. CountIt count = delegate(int end) { for (int i = 0; i <= end; i++) { Console.WriteLine(i); } }; count(3); Console.WriteLine(); count(5); }
static void Main(string[] args) { CountIt count = delegate(int end) { //этот кодовый блок передается делегату for (int i = 0; i <= end; i++) { Console.WriteLine(i); } }; count(3); Console.WriteLine(); count(5); }
static void Main() { // Далее следует код для подсчета чисел, передаваемый делегату // в качестве анонимного метода. CountIt count = delegate { // Это кодовый блок передается делегату. for (int i = 0; i <= 5; i++) { Console.WriteLine(i); } }; // Обратите внимание на точку с запятой. count(); }
public static CountIt Counter() { int sum = 0; CountIt ct = delegate(int end) { sum = 0; for (int i = 0; i <= end; i++) { sum += i; } return(sum); }; return(ct); }