Yes, there is a lot of difference in how to develop, but not in language.
The C # language is exactly the same on any platform. Syntax and features of the language you will have on any platform that you will develop. That's why she's so cool. You will learn a language and can deliver products to any platform: Desktop, App Store, Mobile, Xbox, Web, IoT, Cloud, Scripts, etc ...
But the mode of development changes completely from platform to platform. This is due to the very characteristics and environments of these platforms. Web is request-oriented, Desktop to events, Mobile Apps there are platform-specific concerns, IoT is an endless loop, Cloud in scalability and decoupling, Xbox in a level of performance that in others we do not care, Scripts then is another world. But all this with the same C #.
Trying to get closer to your question:
Can a function executed by a button on a desktop App run by a button on an App mobile?
-
Simple answer: SIM
-
Correct answer: Depends
If the function being called has a good decoupling level - it has no dependencies - it can be done very smoothly.
A legal example. You make a WinForms to add two numbers:
protected void btnSomar_Click(object sender, EventArgs e)
{
var primeiro = int.Parse(txtPrimeiro.Text);
var segundo = int.Parse(txtSegundo.Text);
lblResultado.Text = (primeiro + segundo);
}
Simple but very poorly written function, because it has a very high level of coupling and dependencies. To make a sum, it depends on having object
, arguments EventArgs
, two TextBox
'es, and Label
to display the result. Migrating this to another platform is impossible. You really have to code everything over again.
But if we isolate the function of adding it like this:
public interface IAdicao
{
int Somar(int primeiro, int segundo);
}
public class Adicao : IAdicao
{
public int Somar(int primeiro, int segundo)
{
return primeiro + segundo;
}
}
We can use it in our WinForms perfectly:
private readonly IAdicao _adicao = new Adicao();
protected void btnSomar_Click(object sender, EventArgs e)
{
var primeiro = int.Parse(txtPrimeiro.Text);
var segundo = int.Parse(txtSegundo.Text);
var resultado = _adicao.Soma(primeiro, segundo);
lblResultado.Text = resultado.ToString();
}
At first glance, it seems that we complicate more, but not. For now, on the click the button you only have a few conversions to capture screen data and then display result. But most importantly, your business rule, the main Soma()
function is completely isolated, with no dependency, and can be ported to a mobile app, to an IoT, to the Web, which will work without problems and without having to mess with walk in your code.