How to create a sequence of repeated numbers in C#

2 Answers

0 votes
using System;
using System.Linq;

public class Program
{
    public static void Main()
    {
        var numbers = Enumerable.Repeat(3, 7);

		foreach (int n in numbers) {
			Console.WriteLine(n);
		}
    }
}
   
 
 
/*
run:
 
3
3
3
3
3
3
3
 
*/
  

 



answered May 8, 2020 by avibootz
0 votes
using System;
using System.Collections.Specialized; 

public class Program
{
    public static void Main()
    {
		String[] arr = new String[] { "c#", "c++", "c", "php" }; 

		StringCollection sc = new StringCollection(); 
        sc.AddRange(arr); 
  
        foreach (string s in sc) {
            Console.WriteLine(s);
        }
    }
}



/*
run:
 
c#
c++
c
php
 
*/
  

 



answered May 8, 2020 by avibootz
...