C-Sharp: verschil tussen versies

Uit Wikikids
Naar navigatie springen Naar zoeken springen
Regel 21: Regel 21:
   
 
String bericht = "hallo";
 
String bericht = "hallo";
  +
 
MessageBox.Show(Bericht + textBox1);
 
MessageBox.Show(Bericht + textBox1);
   
Regel 28: Regel 29:
   
 
En zo zijn er heel veel andere mogelijkheden
 
En zo zijn er heel veel andere mogelijkheden
  +
  +
Dit is een van de voorbeelden:
  +
  +
  +
namespace CodePad
  +
{
  +
public partial class Activation : Form
  +
{
  +
private OleDbConnection connect = new OleDbConnection();
  +
  +
public Activation()
  +
{
  +
InitializeComponent();
  +
  +
connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Server=https://osgs-f68a03a634f899.sharepoint.com ;Database=CodePad Keys;Jet OLEDB:Database;Password=lol;
  +
Authentication=365;SSL=True;";
  +
}
  +
  +
private void Activate_Click(object sender, EventArgs e)
  +
{
  +
try
  +
{
  +
connect.Open();
  +
  +
OleDbCommand cmd = new OleDbCommand();
  +
  +
cmd.Connection = connect;
  +
  +
cmd.CommandText = "select * from CodePad Keys where ProductID= '" + textBox1.Text + "' and ProductKey= '" + textBox2.Text + "'";
  +
  +
OleDbDataReader read = cmd.ExecuteReader();
  +
  +
int count = 0;
  +
  +
while (read.Read())
  +
{
  +
count = count + 1;
  +
}
  +
if (count == 1)
  +
{
  +
MessageBox.Show("The license key is correct, the program is activated", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information);
  +
  +
Properties.Settings.Default.Activated = true;
  +
  +
Properties.Settings.Default.Save();
  +
}
  +
if (count > 1)
  +
{
  +
MessageBox.Show("The license key is not correct, the program is NOT activated", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  +
}
  +
else
  +
{
  +
MessageBox.Show("The license key is not correct, the program is NOT activated", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  +
}
  +
connect.Close();
  +
}
  +
catch (Exception ex)
  +
{
  +
MessageBox.Show("A critical error occured, The progam has NOT been activated. Details: " + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  +
}
  +
  +
}
  +
  +
}
  +
}

Versie van 1 okt 2015 23:04

C# ofwel C-Sharp is een programmeertaal onderdeel van het .Net framework van Microsoft. De taal kwam in 2001 uit en is een zeer populaire taal.

Voorbeelden

Voorbeeld 1

Een simpel hello world programma

Code

System.Console.Writeline("Hello World");

Output

Hello World

Voorbeeld 2 Bericht met jouw naam (textBox1)

Code

String bericht = "hallo";

MessageBox.Show(Bericht + textBox1);

Output

Hallo jouw naam

En zo zijn er heel veel andere mogelijkheden

Dit is een van de voorbeelden:


namespace CodePad {

   public partial class Activation : Form
   {
       private OleDbConnection connect = new OleDbConnection();
       public Activation()
       {
           InitializeComponent();
           connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Server=https://osgs-f68a03a634f899.sharepoint.com ;Database=CodePad Keys;Jet OLEDB:Database;Password=lol;

Authentication=365;SSL=True;";

       }
       private void Activate_Click(object sender, EventArgs e)
       {
           try
           {
               connect.Open();
               OleDbCommand cmd = new OleDbCommand();
               cmd.Connection = connect;
               cmd.CommandText = "select * from CodePad Keys where ProductID= '" + textBox1.Text + "' and ProductKey= '" + textBox2.Text + "'";
               OleDbDataReader read = cmd.ExecuteReader();
               int count = 0;
               while (read.Read())
               {
                   count = count + 1;
               }
               if (count == 1)
               {
                   MessageBox.Show("The license key is correct, the program is activated", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information);
                   Properties.Settings.Default.Activated = true;
                   Properties.Settings.Default.Save();
               }
               if (count > 1)
               {
                   MessageBox.Show("The license key is not correct, the program is NOT activated", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
               }
               else
               {
                   MessageBox.Show("The license key is not correct, the program is NOT activated", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
               }
               connect.Close();
           }
           catch (Exception ex)
           {
               MessageBox.Show("A critical error occured, The progam has NOT been activated. Details:    " + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
           }
           
       }
   }

}

Afkomstig van Wikikids , de interactieve Nederlandstalige Internet-encyclopedie voor en door kinderen. "https://wikikids.nl/index.php?title=C-Sharp&oldid=417278"