The problem has been solved with the questions below.
Errors involving C#
So I guess there must be some import (in C# they use the expression
"using" + import), anything that allows me to just
environment to use OOP.
The answer is nay! No additional import/library/framework is required to test object-oriented paradigm resources. The C# natively works oriented to objects, and the failure of the test performed has to do with the lack of knowledge of the PC regarding the implementation of C# with this paradigm, and use of swollen didactic material (which limits to a 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 teaching material, 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 attribute types in the sample code. This defect was corrected 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");
}
}
}
Errors of conceptualization of the object-oriented paradigm
On that line..
objeto c = new Program();
Even if "object" were the actual object, it was not "set", then it does not exist. The explanation why the didactic material did this has already been said above. It is worth mentioning that AP had no intention of using the syntax "Object", which I did not know existed in C#. Another problem is the original title of the question:
How to program orientation to C# objects using . NET CORE?
Although it is still programming the question, it can induce the SOPT user to lecture on the Object Orientation paradigm (the concept), and not the implementation problem (the code). For example, questions may be raised whether a code that does not use any of the pillars of the OOP paradigm (abstraction, encapsulation, inheritance and polymorphism) is in fact OOP. A purist proponent of the paradigm may argue that there must be full use of the pillars. Your opponent will claim that excess inheritance causes coupling. In the end neither of the two will address the implementation in C# (which always has differences between one language and another). For this reason, after the publication of this post, the title of the question and parts of the content will be changed. Still on a third PA error involving OOP, it is assumed that there should be an additional one anyway. This error was also cited in errors involving C#. If such a tool claims to natively support OOP, at least any additional should not be installed/imported/etc. Perhaps this "bizarre" exists in some tool but is open to criticism. Below code of the working class 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 most that happens is a Warning of data 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]
On a fourth error involving this topic, it is in the concept of Camelcase. This is not necessarily an error of OOP, but of good practice. But that induced an OOP error by not noticing the syntax of the Account class.
The problem was solved by seeking information on these concepts.
Response from Stackoverflow in English:
https://stackoverflow.com/questions/43965452/how-to-program-in-oop-by-c-sharp-in-net-core
Object orientation
https://msdn.microsoft.com/pt-br/library/cc580626.aspx?f=255&MSPPError=-2147217396
About Camelcase
https://en.wikipedia.org/wiki/Camel_case
The point is I want to practice the exercises. I want to see it running. I just can’t do it in . NET CORE . E still has the problem of not everything used in . NET framework being used in . NET CORE.
– Paulo Sérgio Duff
When you return, I would like you to complement it with the answer of the English stackoverflow: http://stackoverflow.com/questions/43965452/how-to-program-in-oop-by-sharp-in-net-core/43965612#43965612 I also need lunch :)
– Paulo Sérgio Duff
The first comment does not make sense, it has no relevance to the problem. The answer there solves the problem, but desensina. Follow that and you’ll do wrong forever.
– Maniero
True! But luckily I discovered two things wrong with regard to both C# and OOP, which I did with that implementation. After lunch I will describe this, and it may help those who are learning and going through the same problem.
– Paulo Sérgio Duff
I just saw the end of the edition of your post. When I return I show why there is more than typo.
– Paulo Sérgio Duff
Yeah, there’s the use of local variables like fields, which I say at first.
– Maniero
There’s more to it than that. Soon I’ll put!
– Paulo Sérgio Duff
"Object orientation is just a code organization" +1. And if you could give another by the mention of D/K.
– OnoSendai
@Onosendai that turned out to be the most important thing of all answer :D
– Maniero