tags:

views:

656

answers:

1

i have a piece of code in C#. I am using a string as parameter in the constructor to give the filepath then I want to convert it into Uri to interact with the rest of the code in a different class. How can i do that? Can anyone tell the syntax?

    public string m_DTBook_FilePath;
    public DTBooktoXukConversion(string bookfile)
    {
        m_DTBook_FilePath = bookfile;
        Uri uri = new Uri(m_DTBook_FilePath);
    }

Whats wrong in this syntax?

+1  A: 

There's nothing wrong with that syntax. What's going wrong when you try it?

Note that in the snippet you've given, you don't do anything with the Uri after constructing it - if the problem is that later you're trying to use m_DTBook_FilePath as a Uri, then you should actually have:

public Uri m_DTBook_FilePath;
public DTBooktoXukConversion(string bookfile)
{
    m_DTBook_FilePath = new Uri(bookfile);
}

(I would strongly recommend against having a public field in your real code, by the way.)

Jon Skeet
Especially prefixed with "m"
John Rasch
There wasnt error.i just wanted to confirm.i adopt ur method, and do this:switch (m_DTBook_FilePath){case "*.opf": el(); break;case "*.xml":tr();break;}In switch field error is:A value of integral type expected.In case field, error is: cannot convert implicitly string to uri