Nora
Nora
CC#
Created by Nora on 2/4/2023 in #help
✅ Help with absorbing basic concepts learned
6 replies
CC#
Created by Nora on 1/4/2023 in #help
✅ How to implement a method of a class using the object which called it as its parameter
I want to create a method that uses the object that called it as a parameter.
public class Example
{
//code
}

class Program
{
static void Main()
{
Example ex1 = new Example();
ex1.FooFunction();
}
}
public class Example
{
//code
}

class Program
{
static void Main()
{
Example ex1 = new Example();
ex1.FooFunction();
}
}
It's because I don't want to type lines like
ex1.FooFunction(ex1)
ex1.FooFunction(ex1)
or
cs Example.FooFunction(ex1)
cs Example.FooFunction(ex1)
Much help needed and appreciated!
9 replies
CC#
Created by Nora on 1/2/2023 in #help
✅ Using System.Collections.Generic Wide-ranging Type? (T), but limiting to fewer options
For example, I'd like to create an Add method, that works for int, double, decimal and float. I'd write
public static T Add<T>(T a, T b)
{
return (a+b);
}
public static T Add<T>(T a, T b)
{
return (a+b);
}
But how do I limit T to only the aforementioned four numeric types? Relevant information is appreciated!
18 replies
CC#
Created by Nora on 1/2/2023 in #help
✅ Error CS7036 - while trying to inherit a class
44 replies