DayKnight
DayKnight
CC#
Created by DayKnight on 11/5/2023 in #help
Cannot read sudden images
I am trying to copy an image and then use that copied version of the image. BitmapImage gives an exception saying "Cannot find image path"
BitmapImage image = new BitmapImage(new Uri(fullImagePath, UriKind.Absolute));
BitmapImage image = new BitmapImage(new Uri(fullImagePath, UriKind.Absolute));
Even tho a lot of other images works, only specific images does not work, can it be because of the size? I am using a filter, but that should not be making any errors
Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog();
openFileDialog.Filter = "Image Files (*.jpg; *.jpeg; *.gif; *.bmp; *.png)|*.jpg; *.jpeg; *.gif; *.bmp; *.png";
Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog();
openFileDialog.Filter = "Image Files (*.jpg; *.jpeg; *.gif; *.bmp; *.png)|*.jpg; *.jpeg; *.gif; *.bmp; *.png";
1 replies
CC#
Created by DayKnight on 12/1/2022 in #help
✅ Accsessing Method in another class by object
I have a customer class which contains the method I want to access
public override void GetAllVichles(List<Enrollment> en)
{
//en.Sort();
foreach (var enrollment in en)
{
foreach (var item in enrollment.Enrollments)
{
if (item.CustomerInfo.FirstName == FirstName && item.CustomerInfo.LastName == LastName)
{
Console.WriteLine($"{item.CustomerInfo.FirstName} {item.VichleInfo.vichleList}");
};
}
}
}
public override void GetAllVichles(List<Enrollment> en)
{
//en.Sort();
foreach (var enrollment in en)
{
foreach (var item in enrollment.Enrollments)
{
if (item.CustomerInfo.FirstName == FirstName && item.CustomerInfo.LastName == LastName)
{
Console.WriteLine($"{item.CustomerInfo.FirstName} {item.VichleInfo.vichleList}");
};
}
}
}
I want to call that method in my program.cs inside my foreach
Console.WriteLine("Write name of customer");
string customSearch = Console.ReadLine();
foreach (var item in vichle.vichleList)
{
if(customSearch == item.Owner.FirstName)
{

}
Console.WriteLine("Write name of customer");
string customSearch = Console.ReadLine();
foreach (var item in vichle.vichleList)
{
if(customSearch == item.Owner.FirstName)
{

}
It is supposed to search for customers with the written name Thanks beforehand 🙂
9 replies
CC#
Created by DayKnight on 12/1/2022 in #help
✅ Convert Enum to string
8 replies
CC#
Created by DayKnight on 11/25/2022 in #help
✅ Input into list (Console app)
Program I want the user to keep creating accounts, and then put them inside at list Example of what the student requires
Student Alex = new Student(1, "Mike", "Scmith", new DateTime(1971, 2, 23), 0);
Student Alex = new Student(1, "Mike", "Scmith", new DateTime(1971, 2, 23), 0);
Enrollment x = new();
x.Enrollments = new List<Enrollment>()
{
};

Console.WriteLine("Write students ID:");
Alex.StudentId = Console.ReadLine();
Console.WriteLine("Write FirstName");
Alex.FirstName Console.ReadLine();
Console.WriteLine("Write LastName");
Alex.LastName Console.ReadLine();
Console.WriteLine("Write BirthDate");
Alex.StudentId Console.ReadLine();
Enrollment x = new();
x.Enrollments = new List<Enrollment>()
{
};

Console.WriteLine("Write students ID:");
Alex.StudentId = Console.ReadLine();
Console.WriteLine("Write FirstName");
Alex.FirstName Console.ReadLine();
Console.WriteLine("Write LastName");
Alex.LastName Console.ReadLine();
Console.WriteLine("Write BirthDate");
Alex.StudentId Console.ReadLine();
Studen Class
public class Student : PersonalInformation
{
public Student(int studentId, string firstName, string lastName, DateTime dateoftime, int age) : base(firstName, lastName, age)
{
StudentId = studentId;
}


public int StudentId
{
get;
set;
}
public class Student : PersonalInformation
{
public Student(int studentId, string firstName, string lastName, DateTime dateoftime, int age) : base(firstName, lastName, age)
{
StudentId = studentId;
}


public int StudentId
{
get;
set;
}
I am just not sure how to make an entire new object containing the given information, what should I do?
6 replies
CC#
Created by DayKnight on 11/24/2022 in #help
✅ Polyphormism?
Is this polyphornism? I am not sure, I was told I should make something like this
public abstract void GetAllCourse(Enrollment en, List<Enrollment> enrollments);
public abstract void GetAllCourse(Enrollment en, List<Enrollment> enrollments);
2 replies
CC#
Created by DayKnight on 11/21/2022 in #help
❔ Foreach loop
I am trying to run through my list, but nothing is being printed out, what am I doing wrong?
List<Enrollment> tilmeldingslist = new List<Enrollment>();
Enrollment enroll1 = new Enrollment(Alex, Programmering);
Enrollment enroll2 = new Enrollment(Alex, Matematik);
Enrollment enroll3 = new Enrollment(Alex, Dansk);

foreach (var items in tilmeldingslist)
{
Console.WriteLine(items);
}
List<Enrollment> tilmeldingslist = new List<Enrollment>();
Enrollment enroll1 = new Enrollment(Alex, Programmering);
Enrollment enroll2 = new Enrollment(Alex, Matematik);
Enrollment enroll3 = new Enrollment(Alex, Dansk);

foreach (var items in tilmeldingslist)
{
Console.WriteLine(items);
}
12 replies
CC#
Created by DayKnight on 11/21/2022 in #help
Calculate obj Age [Answered]
Program
DateTime dtBirthDate = new DateTime(1971, 2, 23);
DateTime dtBirthDate = new DateTime(1971, 2, 23);
Student
public DateTime DateOfTime { get; set; }

public int GetAge()
{
var today = DateTime.Now;

var age = today.Year - DateOfTime;

if (DateOfTime.Date > today.AddYears(-age)) age--;

return age;
}
public DateTime DateOfTime { get; set; }

public int GetAge()
{
var today = DateTime.Now;

var age = today.Year - DateOfTime;

if (DateOfTime.Date > today.AddYears(-age)) age--;

return age;
}
I am trying to calculate the age, from the birthdate to now. but I am not sure how to do it when using properties
15 replies
CC#
Created by DayKnight on 11/21/2022 in #help
❔ DateTime Property [Answered]
public DateTime DateOfTime
{
get { return _DateOfTime; }
set { _DateOfTime = value; }
}


Student student1 = new Student(1, "Mike", "Scmith", 2003, 19);
public DateTime DateOfTime
{
get { return _DateOfTime; }
set { _DateOfTime = value; }
}


Student student1 = new Student(1, "Mike", "Scmith", 2003, 19);
What kind of input does DateTime expect?
8 replies
CC#
Created by DayKnight on 11/7/2022 in #help
Programming with Paramerters (SOLVED) [Answered]
14 replies
CC#
Created by DayKnight on 9/21/2022 in #help
Can't read Json in WPF
23 replies
CC#
Created by DayKnight on 9/20/2022 in #help
WPF read and write to Json [Answered]
The title says it all, I don't know how to read and write to Json properly. I tried some things but they don't seem to work
static List<persondata> persondata()
{
string fileName = @"C:\Users\elko\source\repos\JsonData\JsonData\bin\Debug\net6.0-windows\Persons.json";
if (File.Exists(fileName))
{
var persons = JsonConvert.DeserializeObject<List<persondata>>
(File.ReadAllText(fileName));

return persons;
}
return null;
}
}
static List<persondata> persondata()
{
string fileName = @"C:\Users\elko\source\repos\JsonData\JsonData\bin\Debug\net6.0-windows\Persons.json";
if (File.Exists(fileName))
{
var persons = JsonConvert.DeserializeObject<List<persondata>>
(File.ReadAllText(fileName));

return persons;
}
return null;
}
}
i have looked for tutorials guides everywhere, but nothing worked for me. I must be doing something wrong
49 replies
CC#
Created by DayKnight on 9/14/2022 in #help
Not avialible in CSharp 9.0 use 10.0 or greater
8 replies