Program that uses verbatim string [C#]

Posted by senthil | 8:08:00 PM | , | 0 comments »

Extensions GetFileName­WithoutExtension will return the entire file name if there's no extension on the file.Path.GetDirectoryName returns the entire string except the file name and the slash before it.

Syntax


When specifying paths in C# programs, we must use two backslashes "\\" unless we use the verbatim string syntax. A verbatim string uses the prefix character "@". Only one backslash is needed in this literal syntax.
using System;
using System.IO;

class Program
{
    static void Main()
    {
 // ... Verbatim string syntax.
 string value = @"C:\directory\word.txt";
 Console.WriteLine(Path.GetFileName(value));
    }
}
OutPut
word.txt

0 comments

Related Posts Plugin for WordPress, Blogger...