© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
31 replies
Guns

❔ Need help with datetime

I need to create a class which has two fields; name and date. Then create objects of this class. I need to use datetime for the date field. anyone knows what im doing wrong?

so basically;


        static void Main()
        {
 
            //create intances of Employee;
            Employee emp1 = new Employee("James", 25, new DateTime(2000, 5, 1));

            //add employees to list
            List<Employee> employees = new List<Employee>(4);
            employees.Add(emp1);
 
 
            //LINQ Questions;
            //Q1. Return a List of employees that hired after the year 2005
            var queryHiredAfter2005 = from emp in employees
                                      where emp.HireDate.Year > 2005
                                      select emp.Name;
             foreach (var res in queryHiredAfter2005)
            {
                Console.WriteLine(res);
            }
 
    class Employee
    {
        public string name;
        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
            } 
        }

 
        public DateTime hiredate;
 
        public DateTime HireDate { get; set; }
 
        //Constructor;
        public Employee(string _name, int _age, DateTime _hiredate)
        {
            _name = Name;
            _age = Age;
            _hiredate = HireDate;
        }

        static void Main()
        {
 
            //create intances of Employee;
            Employee emp1 = new Employee("James", 25, new DateTime(2000, 5, 1));

            //add employees to list
            List<Employee> employees = new List<Employee>(4);
            employees.Add(emp1);
 
 
            //LINQ Questions;
            //Q1. Return a List of employees that hired after the year 2005
            var queryHiredAfter2005 = from emp in employees
                                      where emp.HireDate.Year > 2005
                                      select emp.Name;
             foreach (var res in queryHiredAfter2005)
            {
                Console.WriteLine(res);
            }
 
    class Employee
    {
        public string name;
        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
            } 
        }

 
        public DateTime hiredate;
 
        public DateTime HireDate { get; set; }
 
        //Constructor;
        public Employee(string _name, int _age, DateTime _hiredate)
        {
            _name = Name;
            _age = Age;
            _hiredate = HireDate;
        }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

DateTimeOffset vs DateTime
C#CC# / help
3y ago
❔ DateTime help with NodaTime
C#CC# / help
4y ago
help datetime
C#CC# / help
4y ago
DateTimeOffset, DateTime, unixtime, localtime, utctime
C#CC# / help
3y ago