当前位置: 首页>>代码示例>>C#>>正文


C# Subject.Single方法代码示例

本文整理汇总了C#中Subject.Single方法的典型用法代码示例。如果您正苦于以下问题:C# Subject.Single方法的具体用法?C# Subject.Single怎么用?C# Subject.Single使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Subject的用法示例。


在下文中一共展示了Subject.Single方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

        public static void Run()
        {
            {
            Console.WriteLine("= Count ==================================");
            var numbers = Observable.Range(0,3);
            numbers.Dump("numbers");
            numbers.Count().Dump("count");
              }

              {
            Console.WriteLine("= Min/Average ==================================");
            var numbers = new Subject<int>();
            numbers.Dump("numbers");
            numbers.Min().Dump("Min");
            numbers.Average().Dump("Average");
            numbers.OnNext(1);
            numbers.OnNext(2);
            numbers.OnNext(3);
            numbers.OnCompleted();
              }

              {
            Console.WriteLine("= First =================================");
            var interval = Observable.Interval(TimeSpan.FromSeconds(3));
            //Will block for 3s before returning
            Console.WriteLine(interval.First());
            // - Use a try/catch blocks around the First() call
            // - Use Take(1) instead. However, this will be asynchronous, not blocking.
            // - Use FirstOrDefault extension method instead
            // Last
              }

              {
            Console.WriteLine("= Single =================================");
            // var numbers = Observable.Range(0,3);
            var numbers = Observable.Range(0,1);
            Console.WriteLine(numbers.Single());
              }
        }
开发者ID:pudae,项目名称:lplpl,代码行数:39,代码来源:Example1.cs

示例2: Single

        public void Single()
        {
            var s = new Subject<int>();
            var l = new List<Notification<int>>();
            {
                s.Single().Materialize().Subscribe(l.Add);

                s.OnNext(10);
                s.OnCompleted();

                l[0].Value.Is(10);
                l[1].Kind.Is(NotificationKind.OnCompleted);
            }

            s = new Subject<int>();
            l.Clear();
            {
                s.Single().Materialize().Subscribe(l.Add);

                s.OnNext(20);
                s.OnNext(30);
                s.OnError(new Exception());

                l[0].Kind.Is(NotificationKind.OnError);
            }

            s = new Subject<int>();
            l.Clear();
            {
                s.Single().Materialize().Subscribe(l.Add);

                s.OnNext(10);
                s.OnError(new Exception());

                l[0].Kind.Is(NotificationKind.OnError);
            }

            s = new Subject<int>();
            l.Clear();
            {
                s.Single().Materialize().Subscribe(l.Add);

                s.OnCompleted();

                l[0].Kind.Is(NotificationKind.OnError);
            }

            s = new Subject<int>();
            l = new List<Notification<int>>();
            {
                s.Single(x => x % 2 == 0).Materialize().Subscribe(l.Add);
                s.OnNext(9);
                s.OnNext(10);
                s.OnCompleted();

                l[0].Value.Is(10);
                l[1].Kind.Is(NotificationKind.OnCompleted);
            }

            s = new Subject<int>();
            l = new List<Notification<int>>();
            {
                s.Single(x => x % 2 == 0).Materialize().Subscribe(l.Add);
                s.OnNext(10);
                s.OnNext(9);
                s.OnCompleted();

                l[0].Value.Is(10);
                l[1].Kind.Is(NotificationKind.OnCompleted);
            }

            s = new Subject<int>();
            l.Clear();
            {
                s.Single(x => x % 2 == 0).Materialize().Subscribe(l.Add);
                s.OnNext(20);
                s.OnNext(30);
                s.OnError(new Exception());

                l[0].Kind.Is(NotificationKind.OnError);
            }

            s = new Subject<int>();
            l.Clear();
            {
                s.Single(x => x % 2 == 0).Materialize().Subscribe(l.Add);

                s.OnNext(10);
                s.OnError(new Exception());

                l[0].Kind.Is(NotificationKind.OnError);
            }

            s = new Subject<int>();
            l.Clear();
            {
                s.Single(x => x % 2 == 0).Materialize().Subscribe(l.Add);

                s.OnCompleted();

//.........这里部分代码省略.........
开发者ID:ragcat,项目名称:UniRx,代码行数:101,代码来源:UnitTests.cs

示例3: Single

 public void Single()
 {
     SetScehdulerForImport();
     var s = new Subject<int>();
     var l = new List<Notification<int>>();
     {
         s.Single().Materialize().Subscribe(l.Add);
         s.OnNext(10);
         s.OnCompleted();
         l[0].Value.Is(10);
         l[1].Kind.Is(NotificationKind.OnCompleted);
     }
     s = new Subject<int>();
     l.Clear();
     {
         s.Single().Materialize().Subscribe(l.Add);
         s.OnNext(20);
         s.OnNext(30);
         s.OnError(new Exception());
         l[0].Kind.Is(NotificationKind.OnError);
     }
     s = new Subject<int>();
     l.Clear();
     {
         s.Single().Materialize().Subscribe(l.Add);
         s.OnNext(10);
         s.OnError(new Exception());
         l[0].Kind.Is(NotificationKind.OnError);
     }
     s = new Subject<int>();
     l.Clear();
     {
         s.Single().Materialize().Subscribe(l.Add);
         s.OnCompleted();
         l[0].Kind.Is(NotificationKind.OnError);
     }
     s = new Subject<int>();
     l = new List<Notification<int>>();
     {
         s.Single(x => x % 2 == 0).Materialize().Subscribe(l.Add);
         s.OnNext(9);
         s.OnNext(10);
         s.OnCompleted();
         l[0].Value.Is(10);
         l[1].Kind.Is(NotificationKind.OnCompleted);
     }
     s = new Subject<int>();
     l = new List<Notification<int>>();
     {
         s.Single(x => x % 2 == 0).Materialize().Subscribe(l.Add);
         s.OnNext(10);
         s.OnNext(9);
         s.OnCompleted();
         l[0].Value.Is(10);
         l[1].Kind.Is(NotificationKind.OnCompleted);
     }
     s = new Subject<int>();
     l.Clear();
     {
         s.Single(x => x % 2 == 0).Materialize().Subscribe(l.Add);
         s.OnNext(20);
         s.OnNext(30);
         s.OnError(new Exception());
         l[0].Kind.Is(NotificationKind.OnError);
     }
     s = new Subject<int>();
     l.Clear();
     {
         s.Single(x => x % 2 == 0).Materialize().Subscribe(l.Add);
         s.OnNext(10);
         s.OnError(new Exception());
         l[0].Kind.Is(NotificationKind.OnError);
     }
     s = new Subject<int>();
     l.Clear();
     {
         s.Single(x => x % 2 == 0).Materialize().Subscribe(l.Add);
         s.OnCompleted();
         l[0].Kind.Is(NotificationKind.OnError);
     }
     UniRx.Scheduler.SetDefaultForUnity();
 }
开发者ID:neuecc,项目名称:UniRx,代码行数:82,代码来源:TestImporter.cs


注:本文中的Subject.Single方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。