Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var foo = "hello";
- Action bar = () => Console.WriteLine(foo);
- bar();
- foo = "goodbye";
- bar();
- class Foo
- {
- public string Text;
- }
- var foo = new Foo();
- foo.Text = "Hello";
- Action bar = () => Console.WriteLine(foo.Text);
- bar();
- foo.Text = "goodbye";
- bar();
- [CompilerGenerated]
- private sealed class <>c__DisplayClass1
- {
- public string foo;
- public void <Main>b__0()
- {
- Console.WriteLine(this.foo);
- }
- }
- var foo = "hello";
- Action bar = [readonly foo]() => Console.WriteLine(foo);
- bar();
- foo = "goodbye";
- bar();
- [CompilerGenerated]
- private sealed class <>c__DisplayClass1
- {
- public readonly string foo;
- public <>c__DisplayClass1(string foo)
- {
- this.foo = foo;
- }
- public void <Main>b__0()
- {
- Console.WriteLine(this.foo);
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ClosureTest
- {
- class Program
- {
- static void Main(string[] args)
- {
- string userFilter = "C";
- IEnumerable<string> query = (from m in typeof(String).GetMethods()
- where m.Name.StartsWith(userFilter)
- select m.Name.ToString()).Distinct();
- while(userFilter.ToLower() != "q")
- {
- DiplayStringMethods(query, userFilter);
- userFilter = GetNewFilter();
- }
- }
- static void DiplayStringMethods(IEnumerable<string> methodNames, string userFilter)
- {
- Console.WriteLine("Here are all of the String methods starting with the letter "{0}":", userFilter);
- Console.WriteLine();
- foreach (string methodName in methodNames)
- Console.WriteLine(" * {0}", methodName);
- }
- static string GetNewFilter()
- {
- Console.WriteLine();
- Console.Write("Enter a new starting letter (type "Q" to quit): ");
- ConsoleKeyInfo cki = Console.ReadKey();
- Console.WriteLine();
- return cki.Key.ToString();
- }
- }
- }
- string userFilter = "C";
- string userFilter_copy = userFilter;
- IEnumerable<string> query = (from m in typeof(String).GetMethods()
- where m.Name.StartsWith(userFilter_copy)
- select m.Name.ToString()).Distinct();
Add Comment
Please, Sign In to add comment