Node Notes

SSH Notes

Visual Basic Notes

Strings

String

ampersand

& - ampersand Generates a string concatenation of two expressions.

Constants Fields

vbNewLine - Represents a newline character for print and display functions.

vbTab - Represents a tab character for print and display functions.

Strings.Format Method

String replace code

{0} - String.Format function returns the fully composed String.

Currency, C, or c

Displays number with thousand separator, if appropriate; displays two digits to the right of the decimal separator. Output is based on system locale settings.

For example, Format(1234567, "c") returns $1,234,567.00.

P, or p

Displays number with thousandths separator multiplied by 100 with a percent sign (%) appended to the right and separated by a single space; always displays two digits to the right of the decimal separator.

Standard, N, or n

Displays number with thousand separator, at least one digit to the left and two digits to the right of the decimal separator.

For example, Format(1234567, "n") returns 1,234,567.00.

Custom Numeric Format Strings

"#" custom format specifier

The "#" custom format specifier serves as a digit-placeholder symbol. If the value that is being formatted has a digit in the position where the "#" symbol appears in the format string, that digit is copied to the result string. Otherwise, nothing is stored in that position in the result string.

Note that this specifier never displays a zero that is not a significant digit, even if zero is the only digit in the string. It will display zero only if it is a significant digit in the number that is being displayed.

The "##" format string causes the value to be rounded to the nearest digit preceding the decimal, where rounding away from zero is always used. For example, formatting 34.5 with "##" would result in the value 35.

CStr

converts literals into Strings.

StringBuilder

is an optimization. A class, it improves common String operations.
Appending,
replacing
and inserting are faster. It is easy to use. With it, we can convert our data back into a String.

The String object is immutable. Every time you use one of the methods in the System.String class, you create a new string object in memory, which requires a new allocation of space for that new object. In situations where you need to perform repeated modifications to a string, the overhead associated with creating a new String object can be costly. The System.Text.StringBuilder class can be used when you want to modify a string without creating a new object. For example, using the StringBuilder class can boost performance when concatenating many strings together in a loop.

0
0
0
s2smodern

Inheritance

Understanding Inheritance

Bookmarks

.netFramework class library (base class library - bcl)

Inheritance Basics (Visual Basic)

(Visual Basic) The Inherits statement is used to declare a new class, called a derived class, based on an existing class, known as a base class. Derived classes inherit, and can extend, the properties, methods, events, fields, and constants defined in the base class. The following section describes some of the rules for inheritance, and the modifiers you can use to change the way classes inherit or are inherited:

  • By default, all classes are inheritable unless marked with the NotInheritable keyword. Classes can inherit from other classes in your project or from classes in other assemblies that your project references.
  • Unlike languages that allow multiple inheritance, Visual Basic allows only single inheritance in classes; that is, derived classes can have only one base class. Although multiple inheritance is not allowed in classes, classes can implement multiple interfaces, which can effectively accomplish the same ends.
  • To prevent exposing restricted items in a base class, the access type of a derived class must be equal to or more restrictive than its base class. For example, a Public class cannot inherit a Friend or a Private class, and a Friend class cannot inherit a Private class.

Inheritance Modifiers

Visual Basic introduces the following class-level statements and modifiers to support inheritance:

  • Inherits statement — Specifies the base class.
  • NotInheritable modifier — Prevents programmers from using the class as a base class.
  • MustInherit modifier — Specifies that the class is intended for use as a base class only. Instances of MustInherit classes cannot be created directly; they can only be created as base class instances of a derived class. (Other programming languages, such as C++ and C#, use the term abstract class to describe such a class.)

Inherits Statement

Causes the current class or interface to inherit the attributes, variables, properties, procedures, and events from another class or set of interfaces.

Remarks

If used, the Inherits statement must be the first non-blank, non-comment line in a class or interface definition. It should immediately follow the Class or Interface statement.

You can use Inherits only in a class or interface. This means the declaration context for an inheritance cannot be a source file, namespace, structure, module, procedure, or block.

Rules

  • Class Inheritance. If a class uses the Inherits statement, you can specify only one base class.

A class cannot inherit from a class nested within it.

  • Interface Inheritance. If an interface uses the Inherits statement, you can specify one or more base interfaces. You can inherit from two interfaces even if they each define a member with the same name. If you do so, the implementing code must use name qualification to specify which member it is implementing.

An interface cannot inherit from another interface with a more restrictive access level. For example, a Public interface cannot inherit from a Friend interface.

An interface cannot inherit from an interface nested within it.

An example of class inheritance in the .NET Framework is the ArgumentException class, which inherits from the SystemException class. This provides to ArgumentException all the predefined properties and procedures required by system exceptions, such as the Message property and the ToString method.

An example of interface inheritance in the .NET Framework is the ICollection interface, which inherits from the IEnumerable interface. This causes ICollection to inherit the definition of the enumerator required to traverse a collection.

MustInherit (Visual Basic)

Specifies that a class can be used only as a base class and that you cannot create an object directly from it.

Remarks

The purpose of a base class (also known as an abstract class) is to define functionality that is common to all the classes derived from it. This saves the derived classes from having to redefine the common elements. In some cases, this common functionality is not complete enough to make a usable object, and each derived class defines the missing functionality. In such a case, you want the consuming code to create objects only from the derived classes. You use MustInherit on the base class to enforce this.

Another use of a MustInherit class is to restrict a variable to a set of related classes. You can define a base class and derive all these related classes from it. The base class does not need to provide any functionality common to all the derived classes, but it can serve as a filter for assigning values to variables. If your consuming code declares a variable as the base class, Visual Basic allows you to assign only an object from one of the derived classes to that variable.

The .NET Framework defines several MustInherit classes, among them Array, Enum, and ValueType. ValueType is an example of a base class that restricts a variable. All value types derive from ValueType. If you declare a variable as ValueType, you can assign only value types to that variable.

Rules

  • Declaration Context. You can use MustInherit only in a Class statement.
  • Combined Modifiers. You cannot specify MustInherit together with NotInheritable in the same declaration.

NotInheritable

Specifies that a class cannot be used as a base class.

Remarks

Alternate Terms. A class that cannot be inherited is sometimes called a sealed class.

The NotInheritable modifier can be used in this context:

FileStream Class

Exposes a Stream around a file, supporting both synchronous and asynchronous read and write operations.

Remarks

Use the FileStream class to read from, write to, open, and close files on a file system, and to manipulate other file-related operating system handles, including pipes, standard input, and standard output. You can use the Read, Write, CopyTo, and Flush methods to perform synchronous operations, or the ReadAsync, WriteAsync, CopyToAsync, and FlushAsync methods to perform asynchronous operations. Use the asynchronous methods to perform resource-intensive file operations without blocking the main thread. This performance consideration is particularly important in a Windows Store app or desktop app where a time-consuming stream operation can block the UI thread and make your app appear as if it is not working. FileStream buffers input and output for better performance.

Stream Class

Provides a generic view of a sequence of bytes. This is an abstract class.

With...End With Statement (Visual Basic)

Executes a series of statements that repeatedly refer to a single object or structure so that the statements can use a simplified syntax when accessing members of the object or structure. When using a structure, you can only read the values of members or invoke methods, and you get an error if you try to assign values to members of a structure used in a With...End With statement.

Overrides (Visual Basic)

Specifies that a property or procedure overrides an identically named property or procedure inherited from a base class.

Remarks

Rules

  • Declaration Context. You can use Overrides only in a property or procedure declaration statement.
  • Combined Modifiers. You cannot specify Overrides together with Shadows or Shared in the same declaration. Because an overriding element is implicitly overridable, you cannot combine Overridable with Overrides.
  • Matching Signatures. The signature of this declaration must exactly match the signature of the property or procedure that it overrides. This means the parameter lists must have the same number of parameters, in the same order, with the same data types.

In addition to the signature, the overriding declaration must also exactly match the following:

  • The access level
  • The return type, if any
  • Generic Signatures. For a generic procedure, the signature includes the number of type parameters. Therefore, the overriding declaration must match the base class version in that respect as well.
  • Additional Matching. In addition to matching the signature of the base class version, this declaration must also match it in the following respects:
  • Shadowing and Overriding. Both shadowing and overriding redefine an inherited element, but there are significant differences between the two approaches. For more information, see Shadowing in Visual Basic.

The Overrides modifier can be used in these contexts:

Function Statement

Property Statement

Sub Statement

MustOverride (Visual Basic)

Visual Studio 2013

Specifies that a property or procedure is not implemented in this class and must be overridden in a derived class before it can be used.

Remarks

You can use MustOverride only in a property or procedure declaration statement. The property or procedure that specifies MustOverride must be a member of a class, and the class must be marked MustInherit (Visual Basic).

Rules

  • Incomplete Declaration. When you specify MustOverride, you do not supply any additional lines of code for the property or procedure, not even the End Function, End Property, or End Sub statement.
  • Combined Modifiers. You cannot specify MustOverride together with NotOverridable, Overridable, or Shared in the same declaration.
  • Shadowing and Overriding. Both shadowing and overriding redefine an inherited element, but there are significant differences between the two approaches. For more information, see Shadowing in Visual Basic.
  • Alternate Terms. An element that cannot be used except in an override is sometimes called a pure virtual element.

The MustOverride modifier can be used in these contexts:

Function Statement (Visual Basic)

Property Statement

Sub Statement (Visual Basic)

0
0
0
s2smodern

SSL Checker

Server Hostname:

(e.g. www.google.com)
Check SSL

| |

Copyright © 2017. All Rights Reserved.

SiteLock