开发者

foreach with uri in

Hey looking through the net I can't seem to find a solution on how to pull these values out of this column of mine, I have only been developing for a year at Uni so this is all new to me.

Basically I don't know how to do it, and reading up on Linq to SQL as well as conditional statements and loops hasn't brought me any clo开发者_开发百科ser to finding my solution.

It's as simple as this statement below:

public void SendToast(string title, string message)
{
    var toastMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
        "<wp:Notification xmlns:wp=\"WPNotification\">" +
        "<wp:Toast>" +
            "<wp:Text1>{0}</wp:Text1>" +
            "<wp:Text2>{1}</wp:Text2>" +
        "</wp:Toast>" +
        "</wp:Notification>";
    var messageBytes = System.Text.Encoding.UTF8.GetBytes(toastMessage);
    using (clientsDBDataContext clientDB = new clientsDBDataContext())
    {
        var client = new ServiceFairy.clientURI();
        foreach (string r in client.uri)
        {
            Uri rs = new Uri(r.ToString());
            SendMessage(rs, messageBytes, NotificationType.Toast);
        }
    }
}

I know for a fact I am doing it wrong but I just cant get my hands on how to fix this, if it wouldn't be too much to ask, please explain how I am doing this wrong as I feel useless when I have to ask others to help me out with stuff I can't figure out myself.

Thanks :)

This is the error Message I am getting:

Error   1   Cannot convert type 'char' to 'string'


What is this line doing?

var client = new ServiceFairy.clientURI();

Aside from the fact that this wouldn't compile (it needs to be new ServiceFairy()), what does clientURI() return? You use it here like this:

foreach (string r in client.uri)

I suspect that client.uri is actually a string. If not, what is it? Assuming it's a string, then looping over any string in C# results in looping over the characters in the string. So I expect your compiler error is due to the fact that you are declaring r as a string, but it's actually a char. Most likely you don't need a loop at all, but I can't answer that until you explain what client.uri actually returns.

And if you're feeling generous, perhaps you can explain why you have a class named ServiceFairy. ;)

Edit:
Based on the comments, the code should go from:

var client = new ServiceFairy.clientURI();
foreach (string r in client.uri)
{
    Uri rs = new Uri(r.ToString());
    SendMessage(rs, messageBytes, NotificationType.Toast);
}

To:

var client = new ServiceFairy.clientURI();
Uri rs = new Uri(client.uri);
SendMessage(rs, messageBytes, NotificationType.Toast);


I suspect client.uri is just a single string, not an array of string[]. So the foreach is iterating through each char in the string.

So you can change it to: foreach(char r in client.uri) {... but I don't think that's what you want.

Just ditch the whole foreach loop and do:

Uri rs = new Uri(client.uri);
SendMessage(rs, messageBytes, NotificationtType.Toast);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜