コード例 #1
0
        public static void Start()
        {
            Student stud = new Student()
            {
                Age = 25
            };

            //Anonymous Method
            IsAdult isAdult = delegate(Student s) { return(s.Age > 18); };

            Console.WriteLine(isAdult(stud));

            //Lambda Expression
            //IsAdult isAdultLE = (Student s) => s.Age > 18; OR
            IsAdult isAdultLE = s => s.Age > 18;

            Console.WriteLine(isAdultLE(stud));

            //Lambda Expression Multi Parameter
            IsAdultPerCountry isAdultPerIndia = (s, minAge) =>
            {
                Console.WriteLine($"Student Age: {s.Age}, MinAge:{minAge}");
                return(s.Age >= minAge);
            };

            Console.WriteLine(isAdultPerIndia(stud, 18));
        }
コード例 #2
0
ファイル: LambdaExamples.cs プロジェクト: hinata7010/CSharp
        static void Main(string[] args)
        {
            Func <int, int> square = x => x * x;

            Console.WriteLine(square(5));
            int[] numbers        = { 2, 3, 4, 5 };
            var   squaredNumbers = numbers.Select(x => x * x);

            Console.WriteLine(string.Join(" ", squaredNumbers));
            Action line = () => Console.WriteLine();

            line();
            CalcMethod add      = (a, b) => a + b;
            CalcMethod subtract = (a, b) => a - b;

            Console.WriteLine(add(10, 20));
            Console.WriteLine(subtract(10.5, 20));
            IsTeenAger isTeenAger = delegate(Student s) { return(s.Age > 12 && s.Age < 20); };
            Student    s1         = new Student()
            {
                Name = "John", Age = 18
            };

            Console.WriteLine("{0}은 {1}.", s1.Name, isTeenAger(s1) ? "청소년입니다" : "청소년이 아닙니다");
            IsAdult isAdult = (s) => {
                int adultAge = 18;
                return(s.Age >= adultAge);
            };
            Student s2 = new Student()
            {
                Name = "Robin", Age = 20
            };

            Console.WriteLine("{0}은 {1}.", s2.Name, isAdult(s2) ? "성인입니다" : "성인이 아닙니다");
        }
コード例 #3
0
 static void Calculate(Student s, IsAdult callBack)
 {
     if (s.Age > 18)
     {
         callBack(s);
     }
     // OR callBack.Invoke(s);
 }
コード例 #4
0
 static void CalculateMultiCast(Student s, IsAdult callBack)
 {
     if (s.Age < 5)
     {
         callBack -= StudentIsNotAKid; // Bad coding style to expose delegate like
     }
     if (s.Age > 18)
     {
         callBack(s);
     }
 }
コード例 #5
0
ファイル: ControllerLogin.cs プロジェクト: linxscc/LoveGame
        public override int GetHashCode()
        {
            int hash = 1;

            if (Ret != 0)
            {
                hash ^= Ret.GetHashCode();
            }
            if (AccountId.Length != 0)
            {
                hash ^= AccountId.GetHashCode();
            }
            if (ChannelAccountId.Length != 0)
            {
                hash ^= ChannelAccountId.GetHashCode();
            }
            if (Channel.Length != 0)
            {
                hash ^= Channel.GetHashCode();
            }
            if (ChannelInfo.Length != 0)
            {
                hash ^= ChannelInfo.GetHashCode();
            }
            if (TimeStamp != 0L)
            {
                hash ^= TimeStamp.GetHashCode();
            }
            hash ^= users_.GetHashCode();
            if (Addication != 0)
            {
                hash ^= Addication.GetHashCode();
            }
            if (IsAdult != 0)
            {
                hash ^= IsAdult.GetHashCode();
            }
            if (Token.Length != 0)
            {
                hash ^= Token.GetHashCode();
            }
            if (PayLink.Length != 0)
            {
                hash ^= PayLink.GetHashCode();
            }
            return(hash);
        }
コード例 #6
0
        public static void Start()
        {
            Console.WriteLine("Print: Delegate");
            Calculate(new Student()
            {
                Age = 25
            }, StudentIsAdult);

            Console.WriteLine("Print: Multicast Delegate");
            IsAdult printDel = StudentIsAdult;

            printDel += StudentIsNotAKid;
            CalculateMultiCast(new Student()
            {
                Age = 25
            }, printDel);
        }
コード例 #7
0
 public bool AllowAdultAccess()
 {
     return(IsAdult.IsSatisfiedBy(this));
 }
コード例 #8
0
 /// <summary>
 /// Filter by if the media's intended for 18+ adult audiences.
 /// </summary>
 public GraphQueryArgument <bool> IsAdultArgument(bool value)
 {
     return(IsAdult.GetQueryArgumentAndSetValue(value));
 }