C
Join ServerC#
help
beginner help
DDown10/23/2022
Hi so im new and i need to present in code this things:
Defining a class,
Field vs Property
Calling functions from the base class
Constructors
Static function
Static field
I know how to make few of them but still would be nice if you show me
Defining a class,
Field vs Property
Calling functions from the base class
Constructors
Static function
Static field
I know how to make few of them but still would be nice if you show me
Xx0rld10/23/2022
it looks like a homework to do 👀
DDown10/23/2022
Not exactly a homework but yeah its school thing
DDown10/23/2022
Can i get help with it there ?
Xx0rld10/23/2022
you will not learn if you just get the solution
what makes you struggle ?
what makes you struggle ?
DDown10/23/2022
The Field vs property and constructors the most
DDown10/23/2022
The calling functions from base all i struggle with is when should i use
base(something)
and when base.something
Xx0rld10/23/2022
a property is a field with a getter/setter define
Xx0rld10/23/2022
public class MyClass
{
// this is a field. It is private to your class and stores the actual data.
private string _myField;
// this is a property. When accessed it uses the underlying field,
// but only exposes the contract, which will not be affected by the underlying field
public string MyProperty
{
get
{
return _myField;
}
set
{
_myField = value;
}
}
// This is an AutoProperty (C# 3.0 and higher) - which is a shorthand syntax
// used to generate a private field for you
public int AnotherProperty { get; set; }
}
DDown10/23/2022
O okay now i get it so they have Like built in get and set methods
Xx0rld10/23/2022
yeah
Xx0rld10/23/2022
and for example if you want to tranform your instance of a class in json you need to have some properties cause it doesn't detect field
Xx0rld10/23/2022
just use them all the time 😄
DDown10/23/2022
Okay
DDown10/23/2022
How about the constructors and base keyword
Xx0rld10/23/2022
the contructor is a normal method but it return a new instance of your object and you have to call it like your class name
DDown10/23/2022
Okay and i can have many of them right
Xx0rld10/23/2022
yeah you can have multiple constructors
DDown10/23/2022
Okay okay
DDown10/23/2022
Now this one
Xx0rld10/23/2022
i've always used the base(x)
I don't really have exeperience with inheritance in c#
I don't really have exeperience with inheritance in c#
DDown10/23/2022
Oh okay
Xx0rld10/23/2022
as I see the
base(something)
is only to call the parent constructor