Create a solution and two more projects
One is the control project. Modify the compilation result path in the property to the bin directory of the second project.
The first project is the Control Project:
Using system;
Using system. Web. UI;
Namespace mspress. servercontrols
{
Public class primegenerator: Control
{
Public int number {Get; set ;}
Protected override void render (htmltextwriter writer)
{
Int [] primes = sieve. getprives (number );
Writer. Write ("primes less than or equal :");
Writer. Write (number );
Writer. Write ("<br> ");
For (INT I = 0; I <primes. length; I ++)
{
Writer. Write (primes [I]);
Writer. Write (",");
}
Writer. Write ("<br> ");
}
}
}
____
Class for calculating prime numbers:
Using system;
Using system. collections;
Namespace mspress. servercontrols
{
Internal sealed class sieve
{
Private sieve (){}
Public static int [] getprives (int n)
{
Bitarray flags = new bitarray (n + 1, true );
For (INT I = 2; I <= (INT) math. SQRT (n); I ++)
{
If (flags [I])
{
For (Int J = I; j * I <= N; j ++)
{
Flags [I * j] = false;
}
}
}
Int COUNT = 0;
For (INT I = 2; I <= N; I ++)
{
If (flags [I]) Count ++;
}
Int [] primes = new int [count];
For (INT I = 2, j = 0; j <count; I ++)
{
If (flags [I]) primes [J ++] = I;
}
Return primes;
}
}
}
___________
The second project is to use the server control class:
Add:
<% @ Register tagprefix = "prime" namespace = "mspress. servercontrols" assembly = "mspress. servercontrols" %>
And
<Prime: primegenerator id = "simple1" runat = "server" number = "19"/>