
MFileStream.Write(bytes, 0, bytes.

'Here is where we actually write to both streamsĭim bytes As Byte() = Encoding.GetBytes(value) 'First we need to get the bytes to write, we do this by calling the GetBytes function from the encoding and passing the string Public Overrides Sub Write(ByVal value As String) Basically, we are just adding a new line to the end of the message and calling the Write function 'Here we are overriding the WriteLine function. Public Overrides Sub WriteLine(ByVal value As String) Return mEncoding 'Returns the encoding we took from the original console stream 'Required, as Encoding is declared as MustOverride in the TextWriter class Public Overrides ReadOnly Property Encoding As Encoding 'Constructor: takes the encoding and console stream from the original console output and the filestream to write to Public Sub New(ByVal encoding As Encoding, ByVal fStream As FileStream, ByVal consoleStream As Stream) Private mConsoleStream As Stream 'Stores the Stream to write to (so the messages still appear on the console window), this is also passed from the original Console Output Stream Private mFileStream As FileStream 'Stores the FileStream to write to (the log file) Private mEncoding As Encoding 'Stores the encoding, passed from the original Console Output Stream The temptation to hide warnings in Visual Studio’s “Error List” window can lead to a buildup of hidden or ignored warnings.Inherits TextWriter 'This is the original class for the console's output This very common issue erodes the strict type checking provided by the C# compiler. In Visual Studio, do this by putting your cursor over the object’s name and pressing F12.įor a more in-depth explanation of the reference/value error, see this tutorial. To fix the problem, look at definitions of the object types. Point point1 = new Point(20, 30) Ĭonsole.WriteLine(point1.X) // 20 (does this surprise you?)Ĭonsole.WriteLine(pen1.Color) // Blue (or does this surprise you?)

The example below shows a couple of unwanted surprises. In C#, the programmer who writes the object decides whether the value assigned to it is a value or a reference to another object. Using a Reference Like a Value or Vice Versa There’s a great tutorial that gives more detail on fixing this issue here.

#VB NET 2010 CONSOLE APPLICATION LINE HOW TO#
#VB NET 2010 CONSOLE APPLICATION LINE CODE#

NET exception gets thrown whenever we try to use a class reference that’s set to null/Nothing, when the code expects otherwise.
