Wednesday, November 16, 2005

Cool File Functions in .NET 2.0

For A Recent Project I had to extract BLOBS stored in DB and write them in the file system. Turns out, there is a cool file system function which just lets you write an entire byte array to disk!!

byte[] bFile = new byte[filesize];
bFile = (byte[])ds.Tables[0].Rows[nCounter]["FILE_DATA"];
System.IO.File.WriteAllBytes(fileURL, bFile);

The WriteAllBytes is an out of the box function that just takes the file path and name along with the byte arrary and just creates the file for you IF the directories specified in the path exist. Cool huh?

Wednesday, November 02, 2005

Thinking About Generics

A comment on my post on generics had me thinking - the question was simple - So, are generics just custom lists or are there any more uses I can think of? I thought it would be good to pause a little and think on what generics are to answer this question. Here's what i think (I am no expert on generics though:) )
Basically, Generics are a nice way of creating flexible data structures or type safe classes. The basic idea is that we implement the class that providers service in a 'generic' way. A Crude example... Public Class People <T> ... considering that <T> could be a student, friend, relative.... Now we can basically have the methods within the People class essentially work for students, friends and relatives as long they use algorithms with depend on common attributes of all these objects. Possibilities? Unlimited. All arguments are welcome :)