Fonction dans C#
Fermé
Quentin
-
7 juil. 2010 à 17:08
Nico# Messages postés 323 Date d'inscription vendredi 4 janvier 2008 Statut Membre Dernière intervention 28 août 2013 - 7 juil. 2010 à 20:52
Nico# Messages postés 323 Date d'inscription vendredi 4 janvier 2008 Statut Membre Dernière intervention 28 août 2013 - 7 juil. 2010 à 20:52
A voir également:
- Fonction dans C#
- Fonction si et - Guide
- Fonction write c ✓ - Forum C
- Fonction si avec date ✓ - Forum Excel
- Ajout snap par la fonction - Forum Snapchat
- Fonction find vba - Astuces et Solutions
2 réponses
scriptiz
Messages postés
1420
Date d'inscription
dimanche 21 décembre 2008
Statut
Membre
Dernière intervention
14 mai 2013
422
Modifié par scriptiz le 7/07/2010 à 20:46
Modifié par scriptiz le 7/07/2010 à 20:46
Je n'ai pas bien compris ton problème mais voici un petit exemple qui fonctionne au cas où :
"The most successful method of programming is to begin a program as simply as possible, test it, and then add to the program until it performs the required job." -- PDP8 handbook, Pg 9-64
using System;
using System.Windows.Forms;
namespace FunctionTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// On récupère les valeurs des champs de texte
double a = Double.Parse(textBox1.Text);
double b = Double.Parse(textBox2.Text);
label1.Text = calculUn(a, b).ToString();
// this.calculUn(a, b)
label2.Text = calculDeux(a, b).ToString();
// Form1.calculDeux(a, b);
}
// Fonction d'objet
private double calculUn(double x, double y)
{
return x * y;
}
// Fonction de classe
private static double calculDeux(double x, double y)
{
return x + y;
}
}
}
"The most successful method of programming is to begin a program as simply as possible, test it, and then add to the program until it performs the required job." -- PDP8 handbook, Pg 9-64
Nico#
Messages postés
323
Date d'inscription
vendredi 4 janvier 2008
Statut
Membre
Dernière intervention
28 août 2013
102
7 juil. 2010 à 20:52
7 juil. 2010 à 20:52
Slt,
Tu créer une fonction pour ton calcul :
Ensuite dans l'evenement de ton bouton tu fais
Tu créer une fonction pour ton calcul :
private double CalculPhysique (string C, string m, string y)
{
// ici tu mets ton traitement ce qui donne:
//--------- Declaration des variables;
double dC,dm,dy, dresult;
// traitement des données;
dC = Double.Parse(C.Trim()); // repeter a l'identique pour les autre;
dresult = (-dC/(m*y));
return dresult;
}
Ensuite dans l'evenement de ton bouton tu fais
private void button1_Click(object sender, EventArgs e)
{
textboxresultat.text = CalculPhysique(textboxX.text,etc);
}