C#-CAI Flashcards

1
Q

internal class Book

A

//is internal so it cannot be access thought other projects
//new class named book

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

public string title;
public string description;
public int pages;

A

//define the variables/atributes of book class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

public Book(string aTitle, string aAuthor, int aPages)
{
title = aTitle;
description = aAuthor;
pages = aPages;
}

A

// this constructor is gonna recived a title, this titile ll be the variable title.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Book myBook = new Book(“Sample Title”, “Sample Author”, 123);

A

create a new book instance, aka object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

explain this

public string name;
public string description;

    public Hobbies (string name, string description)
    {
        this.name = name;
        this.description = description;
    }
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

static void Main(string[] args) explain it

A

the entry point of a console application (or any .NET Core application that isn’t a library).
Main: This is the name of the method. The Main method is special because the .NET runtime looks for this method as the starting point of the application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

static meaning

static void Main(string[] args)

A

This keyword means that the method belongs to the type itself, rather than an instance of the type. In other words, you don’t need to create an object of the class to call a static method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

create a method for the class. Do I need to pass the props/atributes?

A

public bool isAvailable()
{
if (pages == 0)
{
return false;
}

 return true;

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what is a getter and a setter?

A

Using getters and setters, you can:

Validate data before it’s stored in an object.
Transform data before it’s returned or stored.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what is a constructor?

A

A constructor is a special method in a class that gets executed whenever an instance of the class is created. Constructors are used to initialize the object’s state, meaning its properties or fields, and to perform any setup or validation that’s required when the object is instantiated

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Is getter and setter get called in the constructor?

A

In the constructor of the Person class, we’re using the Name property to set the name. This means that the setter for Name will be called when you create a new Person object using this constructor. The getter will only be called when you attempt to access the value of the Name property.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

the constructor shouldent return something?

A

NO! The error you’re seeing is because constructors don’t have a return type, not even void. In C#, the casing (capitalization) of identifiers matters. If the constructor’s name doesn’t exactly match the class name (in terms of casing), the C# compiler thinks it’s a method, which is why you’re getting an error about returning something.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what is encapsulation?

A

The field _name is private, meaning it cannot be accessed directly outside of the TVShow class. Instead, we provide controlled access to that field via a public property, in this case Name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

underscore convetion means…

A

By convention, private fields sometimes start with an underscore.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

purpose of return value of a property by the set/get by the Name public property that controls de private _name field/property of the object. Why?

A

You’re accessing the Name property of the show object, which internally retrieves the value from the _name field. This indirect access allows the class to enforce any rules or behaviors around getting or setting the value, instead of directly exposing the field.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

what is an static method?

A

is a method that does not requires to instance a class.
It cannot directly access instance members (fields, properties, or non-static methods). Instead, it can only access static members.

17
Q

Inheritance.

A

In C#, inheritance allows you to create a new class that is based on an existing class. The new class inherits attributes and behaviors (i.e., fields and methods) from the existing class.

18
Q

Example of inheritance.

A

Chef and ItalianChef.

class ItalianChef : Chef{}

superClass/parent class and class/children class