It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I have an array of object called objStud within it has another array
how do I loop and display them?
Here is an image that you can see how objStud is like
Just use nested foreach statements
foreach (Student stud in objStud)
{
foreach (Fee in stud.Fees)
{
// Do something with stud and/or fee
}
}
You can use SelectMany to flatten first:
foreach(var fee in objStud.SelectMany(x => x.Fees))
{
}
You can use "foreach" in looping and displaying the values. This is a very easy and good example on how to access the data that you want to display.
This will also teach you the concept behind array. Have fun!
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am building a list from a dataset as 12345_9876,125675_0987,
I try to remove the last , from the list like we do for strings..
value.TrimEnd(',');
Can we do similar thing for a list?
I hope this will help you?
var lastElement = yourList.ElementAt<string>(yourList.Count - 1).TrimEnd(',');
yourList.RemoveAt(yourList.Count - 1);
yourList.Insert(yourList.Count,lastElement);
Think you just want this?:
List<string mylistfromdataset = // I dunno how you populated it
var newlist = mylistfromdataset.Select(x=> x.TrimEnd(',')).ToList();
EDIT after the poster cleared the question, you could use this 2 line code to make a new list where the last string the , is trimmed.
var list = listofstring.Take(listofstring.Count - 1).ToList();
list.Add(listofstring.Last().TrimEnd(','));
(Make a list excluding the last item. then trim the last item with , at the end and at it to the new list.)
Just use String.Join:
String delimitedList = String.Join(",", yourList);
int i=value.LastIndexOf(",");
if(i!=-1)
value=value.Remove(i,1);
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I`m making an application for an animal shelter, and each time a dog is added to the animal list it has to have the date it last went for a walk. Part of the assignment is to show a list of dogs that are not walked out TODAY. Any ideas?
OK, assuming that you have a "LastWalked" column in your data structure you want something like:
var dogsNotWalked = allDogs.Where(d => d.LastWalked < DateTime.Today);
It would help if you'd try something before asking for help. Not to mention showing your work. It's not exactly difficult, a one-liner, in fact. Try something like this:
public IEnumerable<Dog> Dogs { get ; set ; }
public IEnumerable<Dog> FindDogsNotWalkedRecently( DateTime referenceDate )
{
return Dogs.Where( dog => dog.LastWalkedAt < referenceDate ) ;
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I need to check that a List contains or not values that are greater that a specific value. How could I doing so?
Using LINQ:
bool contains = yourList.Any(z => z.YouProperty > yourValue);
You can use Enumerable.Any<TSource> method. It returns boolean.
Determines whether a sequence contains any elements.
Return Value
Type: System.Boolean
true if the source sequence contains any elements; otherwise, false.
List.Any(a => a.Property > Value);
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Has been solved. Was trying to create a do statement that would not do anything until the while was checked. Was solved by simply putting an if statement before the do statement.
Using a do statement and anything else you might need, write the equivalent of:
while (b) {
s;
}
I think you might be looking for
if(b)
{
do
{
s;
}
while(b);
}
Is a standard part of the language:
do
{
s;
} while (b);
If I understood your question correctly you have a code that uses do..while loop and you want to replace it with a "regular" while loop.
That is not so simple as you say in your example. The difference is that do..while will always run at least once, and check the condition after it's completed. While loop may not run at all.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
How to store a List<> object in WP7 Local Database?
List<CheckBox> lcb = myListBox.Items.OfType<CheckBox>()
.Where(c => c.IsChecked == true).ToList();
I used OfType instead of Cast because OfType will work even if there a single checkbox item or all items are checkboxes.
In case to Cast it will give error if even a single item is not checkbox.