然後,你可以單擊“新建”鏈接創建規則表達式(以後也可以使用“編輯”鏈接再修改之)。表達式創建窗口如下所示:
[注意]上面的表達式後面不允許有分號“;”,否則會出現錯誤提示。
3.同樣方式創建內循環活動whileActivity2的規則條件為:
this.j <= this.i
4.根據前面的算法分析,我們要分別創建內外循環活動的
private void codeActivity1_ExecuteCode(object sender, EventArgs e)
{
j = 1;
i++;
}
private void codeActivity2_ExecuteCode(object sender, EventArgs e)
{
if (i == j)
{
Console.Write("{0} * {1}={2} ", i, j, i * j);
Console.WriteLine("");
}
else
Console.Write("{0} * {1}={2} ", i, j, i * j);
j++;
}
5.下面是完整的工作流類定義代碼:
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.ActivitIEs;
using System.Workflow.ActivitIEs.Rules;
namespace WhileActiviity
{
public sealed partial class Workflow1 : SequentialWorkflowActivity
{
//創建兩個控制內外層循環的變量
private int i = 0;
private int j = 1;
public Workflow1()
{
InitializeComponent();
}
private void codeActivity1_ExecuteCode(object sender, EventArgs e)
{
j = 1;
i++;
}
private void codeActivity2_ExecuteCode(object sender, EventArgs e)
{
if (i == j)
{
Console.Write("{0} * {1}={2} ", i, j, i * j);
Console.WriteLine("");
}
else
Console.Write("{0} * {1}={2} ", i, j, i * j);
j++;
}
private void codeActivity3_ExecuteCode(object sender, EventArgs e)
{
Console.Read();
}
}
}
自不必贅述了吧。
四、運行實例
按F5運行控制台程序,一般順利的話,將得到如下圖所示運行時快照。