DustinMarino
DustinMarino
CC#
Created by DustinMarino on 1/9/2023 in #help
❔ Question about data types and classes
object cube1 = new Cube(7); what exactly happens here when i have a different variable type but I still set it equal to a new (whatever the class is) with the class being different than the data type. - so here I have the data type object but setting it equal to new Cube. how does it work when u do something like this. does the variable still use the methods and properties in cube because it is set as new cube or not because the datatype is object?
7 replies
CC#
Created by DustinMarino on 1/9/2023 in #help
❔ As Keyword
when should you use the "as" key word?
7 replies
CC#
Created by DustinMarino on 1/7/2023 in #help
❔ Polymorphism
can someone give a very simple example of polymorphism?
7 replies
CC#
Created by DustinMarino on 1/6/2023 in #help
❔ IEquatable
Hello. The course I am taking is discussing interfaces. What is the point of putting IEquatable<Ticket> next to the class name below? Because I took away the IEquatable<Ticket> just to see what would happen and the Equals method still worked the way it was supposed to so what exactly is the : IEquatable<Ticket> doing and what is the point of using it? using System; namespace Ticket { public class Ticket : IEquatable<Ticket> { // property to store the duration of the ticket in hours public int DurationInHours { get; set; } // simple constructor public Ticket(int durationInHours) { DurationInHours = durationInHours; } public bool Equals(Ticket other) { return this.DurationInHours == other.DurationInHours; } } }
7 replies
CC#
Created by DustinMarino on 1/2/2023 in #help
❔ Lists
i am doing a course and the instructor wanted us to create a list that prints even numbers from 100 to 170. his solution is below and it confuses me because I don't know why he put "public static List<int> Solution()" just to create another list later. What's the need of the first list? public class ListsExercise { public static List<int> Solution() { // TODO: write your solution here //create a new list List<int> myList = new List<int>(); //go thorugh every number beyweem 100 and 170 for (int i = 100; i <= 170; i++) { //check if its an even number if (i % 2 == 0) { //add it to the list myList.Add(i); } } //return the list return myList; } }
6 replies