olleeee
olleeee
CC#
Created by olleeee on 12/4/2023 in #help
creating objects in a different class
Hi, i have just gotten some feedback from handing in a project, my professors says that i have made some errors. I have corrected them but was wondering if anybody could just look through it and see if the comments in agreeing with the changes? https://discord.com/channels/143867839282020352/1181094353683365958/1181094353683365958 here is the code and will post the feedback underneath
5 replies
CC#
Created by olleeee on 12/1/2023 in #help
✅ sort list after property
Hi, im working with a WPF application and trying to do like a candy calculator. I can make everything and put in values, but now im trying to sort out the sorting of the list after a property. So i have done this:
public class Person
{
public int Age { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int Candies { get; set; }

public List<Person> PeopleList { get; set; }


public override string ToString()
{
return $"{FirstName} {LastName}, Age: {Age}, Candies {Candies}";
}

public void DistrubuteCandyByAge()
{

PeopleList = PeopleList.OrderBy(x => x.Age).ToList();
}

public void DistrubuteCandyByFirstname()
{
PeopleList = PeopleList.OrderBy(x => x.FirstName).ToList();

}
public void DistrubuteCandyByLastName()
{
PeopleList = PeopleList.OrderBy(x => x.LastName).ToList();
}
public class Person
{
public int Age { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int Candies { get; set; }

public List<Person> PeopleList { get; set; }


public override string ToString()
{
return $"{FirstName} {LastName}, Age: {Age}, Candies {Candies}";
}

public void DistrubuteCandyByAge()
{

PeopleList = PeopleList.OrderBy(x => x.Age).ToList();
}

public void DistrubuteCandyByFirstname()
{
PeopleList = PeopleList.OrderBy(x => x.FirstName).ToList();

}
public void DistrubuteCandyByLastName()
{
PeopleList = PeopleList.OrderBy(x => x.LastName).ToList();
}
3 replies
CC#
Created by olleeee on 11/30/2023 in #help
✅ List doesnt show multiple inputs
Hi i have this code, and when looping throught all the houses and the second member of each house is put in you can only see one member still in the list, why?
40 replies
CC#
Created by olleeee on 11/30/2023 in #help
✅ WPF, how do i fill listboxes with values
Hi im trying to fill my list with objects and then only display the name what should i do?
public void FillLists(Wizard wizard)
{

lstGryffindor.ItemsSource = hogwarts.Griffendor.Members;
lstHufflepuff.ItemsSource = hogwarts.Hufflepuff.Members;
lstRavenclaw.ItemsSource = hogwarts.Ravenclaw.Members;
lstSlytherin.ItemsSource = hogwarts.Slytherin.Members;

}
public void FillLists(Wizard wizard)
{

lstGryffindor.ItemsSource = hogwarts.Griffendor.Members;
lstHufflepuff.ItemsSource = hogwarts.Hufflepuff.Members;
lstRavenclaw.ItemsSource = hogwarts.Ravenclaw.Members;
lstSlytherin.ItemsSource = hogwarts.Slytherin.Members;

}
7 replies
CC#
Created by olleeee on 11/30/2023 in #help
✅ Lists is the same index all the time.
Hi, i have built different lists for different houses in Hogwarts and now Im trying to add members to the different houses through a sorting hat method. But every time the same house just get members added, why?
public void SortingHat(Wizard wizard, List<House> hogwarts)
{
foreach (House house in hogwarts)
{
house.Members.Add(wizard);
break;
}

}
public void SortingHat(Wizard wizard, List<House> hogwarts)
{
foreach (House house in hogwarts)
{
house.Members.Add(wizard);
break;
}

}
41 replies
CC#
Created by olleeee on 11/29/2023 in #help
✅ Combobox writes out collection instead of the values
Hi im working in a WPF application for a university project thats based on Harry Potter. So i have built Hogwarts, and then put in the different houses, Gryffendor and so and so in different classes and built them after a house class to follow the same criteria. So the story is that you supposed to put in a password, and then fill in in a combobox which house the password is for. But when I do the combobox like bellow it just says collection, and not the differnt houses, why? Also added more code into here: https://paste.mod.gg/
39 replies
CC#
Created by olleeee on 11/28/2023 in #help
✅ Methods
Hi, i need help building a method to see if a textbox contains digits or letters. The assignment is to put in the year you are born and then give back how old you are. The tricky part for me is to build a method that will catch if you put letters in your textbox and not break down. Im not allowed to use any built in methods like tryParse och try and catch. ```cs private void Button_Click(object sender, RoutedEventArgs e) { string yearBorn = TxtYearBorn.Text; bool istrueornot = TryifStringisNumber(yearBorn);
if (istrueornot == false) { MessageBox.Show("Du får bara skriva in siffror"); } else if (istrueornot == true) { int integerYearBorn = int.Parse(yearBorn); int yearBornResult = Age(integerYearBorn); MessageBox.Show($"You are {yearBornResult} years old"); } } public bool TryifStringisNumber(string yearborn) { for (int i = 0; i < yearborn.Length; i++) { if (i <= 0 ) { return false; } else {
return true; } } return false; } private int Age(int yearOfBirth) { if (yearOfBirth >= 0) { return -1; } else { int currentyear = DateTime.Now.Year; return currentyear - yearOfBirth; } }
} }
37 replies
CC#
Created by olleeee on 11/27/2023 in #help
✅ Why is a variable false in project in WPF .Net application even after it should be true?
Hi I'm currently building my first C# project and could really need some help, I'm supposed to take in a password, check if it is correct to the declared passwords in properties and then be able to change the password if the new password follows the right format. Most of the code i have done but struggling a bit now, so could really really need some help.
87 replies