Difference between revisions of "Programmering II Januar 2017"
From Teknologisk videncenter
(→Middel hold) |
(→Middel hold) |
||
Line 13: | Line 13: | ||
decimal convertedInput = decimal.Parse(input); | decimal convertedInput = decimal.Parse(input); | ||
</source> | </source> | ||
+ | |||
+ | |||
+ | |||
+ | Lommeregner eksempel: | ||
+ | |||
+ | https://drive.google.com/file/d/0B5oDizcmFQ1YMzBVMUk3ZUZxbzg/view?usp=sharing | ||
=Expert hold= | =Expert hold= |
Revision as of 14:26, 9 January 2017
Middel hold
Opgave 1:
Lav en BMI beregner som denne:
http://www.beregnbmi.dk/Default.aspx
For at konvertere en string til en decimal bruges følgende kode:
string input = textBox.Text;
decimal convertedInput = decimal.Parse(input);
Lommeregner eksempel:
https://drive.google.com/file/d/0B5oDizcmFQ1YMzBVMUk3ZUZxbzg/view?usp=sharing
Expert hold
Opgave 1:
Lav et program der kan sende data til en applikation som kan lytte. Benyt gerne UDP.
Opgave 2:
Udvid programmet så programmerne kan både sende og modtage data til hinanden. (et simpelt chat program.)
Listener
UdpClient client = new UdpClient(11000);
IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, 11000);
byte[] recivedArray = client.Receive(ref endPoint);
string message = Encoding.ASCII.GetString(recivedArray);
Console.WriteLine("The message was:");
Console.WriteLine(message);
Console.ReadKey();
Sender
string message = "Hello!";
UdpClient client = new UdpClient();
IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 11000);
byte[] bArray = Encoding.ASCII.GetBytes(message);
client.Send(bArray, bArray.Length, endpoint);
Console.WriteLine("Message has been sent!");
Console.ReadKey();