Microsoft Certified Solutions Developer (MCSD) Certification Practice Test

Disable ads (and more) with a membership for a one time $2.99 payment

Prepare for the Microsoft Certified Solutions Developer Certification Test with multiple choice questions and flashcards. Each question comes with hints and explanations. Start mastering your skills now!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


What method is used to write data to a FileStream in C#?

  1. fs.WriteLine(data)

  2. fs.Write(data, 0, data.Length)

  3. fs.Append(data)

  4. fs.WriteFile(data)

The correct answer is: fs.Write(data, 0, data.Length)

The method used to write data to a FileStream in C# is accomplished by invoking the Write method, which is defined as fs.Write(data, 0, data.Length). This method takes three parameters: the data to be written (typically a byte array), an integer specifying the offset in the array from which to begin copying data, and the number of bytes to write from the data source. When using a FileStream, it's essential to work with byte-level operations, as streams handle raw binary data. The Write method effectively handles this by allowing developers to specify exactly how many bytes should be sent to the stream from the data array. In this case, by passing 0 as the starting index and data.Length, you ensure that all available bytes in the data array are written to the FileStream starting from the beginning. Other options mentioned do not correspond to the correct use of the FileStream API in C#. For instance, there is no built-in WriteLine method for FileStream, nor is there a method called Append or WriteFile. Each of these alternatives lacks the correct signature or doesn’t represent the functionality required to write data to a FileStream effectively.