0

If´ve got a xaml-view, which gets some values from a list (from a DB throw a rest-service). so there are some parameters like "id", "phone number" or "adress". Evrybody has an ID, sometimes a phoneNo, sometimes Address or both. now i want to view a list, with the ID, but only with "people" which has got an phone number. that for, i´ve got a listview, in which i´m binding the phone number f.e.:

 ...<viewcell x:Name="people">
                                    <Label Text="ID: "/>
                                    <Label Text="{Binding ID}"/>                                        
                                    <Label Text="PhoneNo: "/>
                                    <Label Text="{Binding PhoneNr}"/>
  </viewcell>...

this is where i set the itemsource:

        people.ItemsSource = retList;

so, as you can see, i will get a list, where all people are listed, sometimes there are phonenumbers, sometimes this field is empty. but i wonly want the peoble with an phonenumber in my list. is this possible? thanks a lot

1 Answer 1

1

Use this:

var phonesList = retList.Where(p => !string.IsNullOrEmpty(p.PhoneNr)).ToList();

Sign up to request clarification or add additional context in comments.

5 Comments

ah damn i ha´ve to ask it in a other way: everybody has got a phonenr, but some are german numbers(+49) and some are swiss numbers (+41) for example. so i´ve got an other value which says "pre-number". so i want only the people, where the pre-no is a swiss one
But the answer will be almost the same except used condition: var phonesList = retList.Where(p => (p.PhoneNr!= null && p.PhoneNr.StartsWith("(+49)"))).ToList();. In every case you will obtain a new list based on existing one under some condition. Am I right this is your goal?
okay thanks a lot. there´s still a little error: in my case, the "phoneNr" is a type of a enum. so it says, there is not the posibility of "StartsWith(...)"
Yes, StartsWith is intended for strings. So you should use something like ...&& p.PhoneNr == YourDesiredValue.
as a string doesnt work.. it´s called Pre_number in my case. so it should be something like: where peoble.pre_number == +49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.