tags:

views:

170

answers:

4

I'd like to add a value to a struct

if (!existISDNteilnehmer(split))
{
    isdnObjs.Add(new ISDN() { name = split, number = "", 
                        channels = new List<string>()});
}                
ISDN? actualISDN = getISDN(split);

if (index < ISDN_teilnehmer.Count())
{
     var numbers = 
          from num in xISDN.XPathSelectElements("//member[name='number']")
               where num.IsAfter(xISDN) &&
                     num.IsBefore(ISDN_teilnehmer.ElementAt(index))
          select num;

     foreach (var nums in numbers)
     {
          if (nums.Element("name").Value == "number")
          {
               var nummer = nums.XPathSelectElements("value");
               var part_nummer = 
                   from n in nummer
                   select n.Value;
               //string temp = part_nummer;

               actualISDN.Value.number = part_nummer;

           }
     }

Everything is read out correctly and the correct number is stored in part_nummer.

Now I want to add the number to the list with actualISDN.Value.number = part_nummer but I get an error that says it cannot be implicitly converted.

Where am I going wrong?

+4  A: 

Don't use var and the problem will become clear.

var part_nummer = from n in nummer
select n.Value;
//string temp = part_nummer;
actualISDN.Value.number = part_nummer;
David B
Dont really understand! If im using "string" part_nummer instead of "var" the problem still exists! :(
cordellcp3
+4  A: 

You're trying to assign a string to an IEnumerable it looks like.

var part_nummer = from n in nummer
    select n.Value;
//string temp = part_nummer;

actualISDN.Value.number = part_nummer;

You should be doing this instead:

var part_nummer = from n in nummer
    select n.Value;
//string temp = part_nummer;

actualISDN.Value.number = part_nummer.FirstOrDefault();
Joseph
Now i got a new error, which says that the return value cannot be changed, cause its not a variable!
cordellcp3
@cordellcp3 What you're saying doesn't make any sense unless you can put it in context of the question you're asking. Please include the errors you're getting in your question so everyone can see what is happening.
Joseph
Just solved the problem in changing the "number"-Value in the list to a List<string> numbers! So i could add values to it! Thanks for the help!
cordellcp3
+2  A: 

When you write this:

var part_nummer = from n in nummer
    select n.Value;

part_nummer contains an IEnumerable<T>. You'd better write something like that:

var nummer = nums.XPathSelectElement("value"); // not XPathSelectElements !
var part_nummer = nummer.Value;

actualISDN.Value.number = part_nummer;
ybo
Now i got a new error, which says that the return value cannot be changed, cause its not a variable!
cordellcp3
I bet the error is in the last line. actualISDN.Value is a *copy* of the ISDN struct. Changes to that copy do not propagate to the "real" value. Try something like ISDN copy = actualISDN.Value;copy.number = part_nummer;actualISDN = copy;
Hans Kesting
Just solved the problem in changing the "number"-Value in the list to a List<string> numbers! So i could add values to it! Thanks for the help!
cordellcp3
A: 

Can't read your code it doesn't render Well on a small screen but taken from the comments try wrapping the part_number linq in (linq goes here).Single()

Rune FS
Just solved the problem in changing the "number"-Value in the list to a List<string> numbers! So i could add values to it! Thanks for the help!
cordellcp3