< Day Day Up > |
TechniqueWhen assigning a literal string to a string object, preface the string with the @ symbol. It turns off all escape-character processing so there is no need to escape path separators: string nonVerbatim = "C:\Windows\Temp"; string verbatim = @"C:\Windows\Temp"; CommentsA compiler error that happens so frequently comes from forgetting to escape path separators. Although a common programming faux pas is to include hard-coded path strings, you can overlook that rule when testing an application. Visual C# .NET added verbatim string syntax as a feature to alleviate the frustration of having to escape all the path separators within a file path string, which can be especially cumbersome for large paths. |
< Day Day Up > |