The issue has been solved with the questions below.
C # errors
Then I imagine that there should be some import (in C # use the expression
"using" + import), anything that allows me to just
environment to use OOP.
The answer is no! No additional import / library / framework is required to test features of the object-oriented paradigm. C # natively works object-oriented, and the failure of the test performed has to do with the lack of knowledge of the AP regarding the implementation of C # with this paradigm, and use of swelling courseware (which limits to certain development environment). The errors will be commented below.
static void Main(string[] args)
{
objeto c = new Program();
c.numero = 12;
c.titular = "João";
c.saldo = 102;
In the third line, the code is following the example of the didactic material.
Conta c = new Conta();
But even in the courseware, the Account class had already declared the type of its attributes.
class Conta
{
int numero;
string titular;
double saldo;
}
The main error was not declaring the types of attributes in the sample code. This bug has been fixed by StackOverFlow in English.
using System;
namespace hwapp {
class Program {
// Aqui embaixo está a correção dos atributos
int numero;
string titular;
int saldo;
static void Main(string[] args) {
var conta = new Program(); // linha corrigida
conta.numero = 12;
conta.titular = "João";
conta.saldo = 102;
Console.WriteLine("Número: "+conta.numero.ToString()+"\n");
Console.WriteLine("Titular da conta: "+conta.titular+"\n");
Console.WriteLine("Saldo: "+conta.saldo.ToString()+"\n");
}
}
}
Object-oriented paradigm conceptualization errors
About this line ..
objeto c = new Program();
Even if "object" was the actual object, it was not "set", so it does not exist. The explanation why the didactic material did this has already been said above. It is worth mentioning that the AP had no intention of using the "object" syntax, which I did not know existed in C #. Another problem is the original title of the question:
How to program object orientation in C # using .NET CORE?
Although the question is still programming, it can induce the user of the SOPT to lecture on the Object Oriented paradigm (the concept), not the implementation problem (the code). For example, questions can be raised if a code that does not use any of the pillars of the OOP paradigm (abstraction, encapsulation, inheritance, and polymorphism) is actually OOP. A purist advocate of the paradigm may claim that there must be full use of the pillars. Your opponent will claim that excess inheritance causes coupling. In the end neither will approach the implementation in C # (which always has differences between one language and another). For this reason, after editing this post, the title of the question and parts of the content will be changed. Still about a third AP error involving OOP, it is to suppose that there should be an additional one anyway. This error was also cited in the C # errors. If such a tool claims that it natively supports OOP, at least any additional should not be installed / imported / etc. Perhaps this "bizarre" exists in some tool but is subject to criticism. Below code of the class running without import.
namespace hwapp {
class Program {
// Aqui embaixo está a correção dos atributos
int numero;
string titular;
int saldo;
static void Main(string[] args) {
var conta = new Program(); // linha corrigida
conta.numero = 12;
conta.titular = "João";
conta.saldo = 102;
}
}
}
The maximum that happens is a Data Warning not being used
Program.cs(6,13): warning CS0414: The field 'Program.numero' is assigned but its value is never used [/home/upgrade/dotnet/hwapp/hwapp.csproj]
Program.cs(8,13): warning CS0414: The field 'Program.saldo' is assigned but its value is never used [/home/upgrade/dotnet/hwapp/hwapp.csproj]
Program.cs(7,16): warning CS0414: The field 'Program.titular' is assigned but its value is never used [/home/upgrade/dotnet/hwapp/hwapp.csproj]
About a fourth error involving this topic, is in the concept of CamelCase. This is not necessarily an OOP bug, but a good one. But that induced an OOP error by not noticing the syntax of the Account class.
The problem was solved by seeking information from these concepts.
StackOverFlow response in English:
link
Object orientation
link
About CamelCase
link