J.S.Orris
J.S.Orris

Reputation: 4831

What Does a Pipe Symbol ("|") in a C# String Do?

The following is a sample line of code:

fDialog.Filter = "SSIS Package (*.dts, *.dtsx)|*.dts;*.dtsx";

What does the pipe symbol do in this string?

Upvotes: 0

Views: 4234

Answers (2)

Stalzer
Stalzer

Reputation: 104

The pipe you are looking at isn't a language feature. It is a delimiter for the string that tells a dialog box what to put into the drop list that can help the user find files known to your application.

There IS a single-pipe "logical or" in C#, but would not typically be seen outside of bitwise logic.

byte byteA = 0;
byte byteB = 1;
long result= byteA | byteB;

Upvotes: 3

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726987

In general, the pipe symbol denotes an OR. However, in this particular context it's interpreted by the file dialog as a separator between descriptions and file name patterns:

Description 1|*.ext1|Description 2|*.ext2|...

The string is split on the pipe, and then the values are paired up. The first string in the pair is the description displayed to end-users, and the second one is the pattern for the file extension.

Upvotes: 3

Related Questions