Hello,
For this problem, you can use nested function to achieve this .
I used a Label to simulate this functionality and loop through the array.
You can refer to my code:
public partial class MainPage : ContentPage
{
string[] numbers = { "one", "two", "three", "four", "five" };
string text = "one";
public MainPage()
{
InitializeComponent();
}
private void Button_Clicked(object sender, EventArgs e)
{
MyLoop(0);
}
public void MyLoop(int count)
{
if (count >= numbers.Length) {
count = 0;
}
text = numbers[count];
Device.StartTimer(TimeSpan.FromMilliseconds(10000), () =>
{
mLabel.Text = text;
MyLoop(++count);
return false;
});
}
}
Note:
When the last element of the data is traversed, the first element is traversed again.
if (count >= numbers.Length) {
count = 0;
}
Best Regards,
Jessie Zhang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.