|
Тема |
Пак да се посмеем на M$ |
|
Автор | user (Нерегистриран) | |
Публикувано | 20.02.05 20:49 |
|
|
Вижте какво намерих в документацията на .NET Framework 1.1 ():
----------------------------------------------------------------
HttpFileCollection MyFileCollection;
HttpPostedFile MyFile;
int FileLen;
System.IO.Stream MyStream;
MyFileCollection = Request.Files;
MyFile = MyFileCollection[0];
FileLen = MyFile.ContentLength;
byte[] input = new byte[FileLen];
// Initialize the stream.
MyStream = MyFile.InputStream;
// Read the file into the byte array.
MyStream.Read(input, 0, FileLen);
// Copy the byte array into a string.
for (int Loop1 = 0; Loop1 < FileLen; Loop1++)
MyString = MyString + input[Loop1].ToString();
----------------------------------------------------------------
Ето някои от проблемите, които аз открих и изпратих на MS (дано feedback-а на MSDN-а някой да го чете):
1) In C# local variables should be in camelCase
2) It is bad practice in C# to define the variables before they are actually needed due to increase of their lifetime and span (It is not VB.NET!)
3) Read method could potentially read less than FileLen bytes. It is bad practice to rely that it will read exactly FileLen bytes
4) Concatenation of strings in loop is well-known bad practice - StringBuilder should be used instead
5) There is a method for convertion from byte array to string - Encoding.ASCII.GetBytes(string)
6) Loop1 is the for-loop is great name for a variable
7) "input" is bad name for the byte array that storers the file contents
Мисля този код да го давам за пример как не трябва да се пише код.
|
| |
|
|
|