Saturday, December 13, 2008

Izračunavanje broja Pi


const int throws = 10000000;
DateTime now = DateTime.Now;
Random rand = new Random ((int) now.Millisecond);
int Inside = 0;
for (int i = 0; i < throws; ++i)
{
double cx = rand.NextDouble();
double cy = rand.NextDouble();
double distance = Math.Sqrt ((cx * cx) + (cy * cy));
if (distance < 1.0)
++Inside;
}
double pi = 4 * (double) Inside / (double) throws;
DateTime End = DateTime.Now;
TimeSpan Diff = End - now;
Console.WriteLine ("pi = " + pi);
Console.WriteLine ("Milliseconds = " + Diff.TotalMilliseconds);
Console.ReadLine();

Friday, December 12, 2008

sample code post - DB Broker

public int ObrisiSveZaUslov(IGhost ighost)
{
string upit = "DELETE *" +
" FROM " + ighost.ImeObjekta +
" WHERE " + ighost.UslovZaNalazenjeSlogova;

var komanda = new OleDbCommand(upit, konekcija, transakcija);

try
{
return komanda.ExecuteNonQuery();
}
catch (Exception)
{
throw new Exception("Greska u radu sa bazom! Brisanje po uslovu");
}
}
пример методе DBBroker-a.
http://feeds.feedburner.com/alisteroz