This is my first reasonably large C# program. Considering my code looks like it was written in an esolang to me, I'm guessing I did something wrong at some point. My main priority is readability, although speed is also a plus.
using System;
public class PrimeSearcher {
public static string Stringilate (int[] iterable) {
string returnable="";
foreach(int i in iterable){
returnable+=i.ToString()+" ";
};
return returnable;
}
public static bool isPrime (int[] iterable,float target) {
foreach(int i in iterable){
if(target%i==0){
return false;
}
if(i==0){ return true; }
//reached the "end" (last discovered prime) of the array, hurray!
}
return true; //will only do anything for the last element
}
static public void Main () {
int[] primes=new int[1000];
float j=2; //float because I think it's the smallest datatype that can return a non-zero number when divided, correct me if I'm wrong
while(primes[primes.Length-1]==0){
if(isPrime(primes,j)){
primes[Array.IndexOf(primes,0)]=(int)j;
}
j++;
}
Console.WriteLine(Stringilate(primes));
//I don't *think* ToString worked when I tried it.
}
}