本文介绍了基本窗口操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用签名方法:



 //测试对Window运算符的理解
/ /我想要开始/结束标记之间的值序列序列
//基因测试序列
var obs =(新列表< int>(){1,2,3,1,4 ,4,2,0,0,1,5,5,5,-1,2,0,0})。ToObservable();

//开始标记是值1
var begin =(来自b in obs
其中b == 1
选择b)
;

//结束标记是值2
var end =(来自e in obs
,其中e == 2
选择e)
;

//其他标记是其余的(不是开始或结束)
var other =(来自o $ obs
其中o!= 1&& o!= 2
选择o)
;

//这不能做我想要的,就是在开始/结束标记之间产生序列
var inner =((来自other.Window中的窗口)(开始,b => ; end.Take(1))
选择窗口

.Switch()
);

inner.Subscribe(i => {Console.WriteLine(" Sequence"); i.Dump();});

我希望以下



序列:


4


4


序列:


5


5


5


-1



但我得到:


序列

解决方案

I'm trying to use the method with signature: http://msdn.microsoft.com/en-us/library/hh211621(v=vs.103).aspx

// Test understanding of Window operator
// I want the sequence of sequence of values which come between begin/end markers
// 	Gen test sequence
var obs = (new List<int>()  { 1, 2, 3, 1, 4, 4, 2, 0, 0, 1, 5, 5, 5, -1, 2, 0, 0 }).ToObservable();

// begin markers are the value 1
var begin = (from b in obs
			where b == 1
			select b)
			;
			
// end markers are the value 2
var end = (from e in obs
			where e == 2
			select e)
			;

// other markers are all the rest (not begin or end)
var other = (from o in obs
			where o != 1 && o != 2
			select o)
			;
			
// This doesn't do what I want, which is to produce sequences between begin/end markers
var inner = ((from window in other.Window(begin, b => end.Take(1))
			    select window
			 )
			.Switch()
			);
			
inner.Subscribe(i => { Console.WriteLine("Sequence"); i.Dump(); });

I would expect the following

Sequence:

4

4

Sequence:

5

5

5

-1

But I get:

Sequence

解决方案


这篇关于基本窗口操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 15:41