PDA

View Full Version : C# Help



Syronix
04-06-2010, 06:55 AM
I'm not sure if I can post this here but I figured it was worth a try. I just started learning C#
and was wondering if anyone could help me with this latest console project I am working on
I'm stuck on Line 58 because I can't figure out how to reference <System.Windows.Forms.dll>
Here's my code

using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace BasicIO
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("***** Basic Console I/O *****");
GetUserData();
FormatNumericalData();
Console.ReadLine();
}
static void GetUserData()
{
// Get name and age.
Console.Write("Please enter your name: ");
string userName = Console.ReadLine();
Console.Write("Please enter your age: ");
string userAge = Console.ReadLine();

// Change echo color, just for fun.
ConsoleColor prevColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Yellow;

// Echo to the console.
Console.WriteLine("Hello {0}! You are {1}.", userName, userAge);

// Restore previous color.
Console.ForegroundColor = prevColor;
}
// now we make use of some format tags.
static void FormatNumericalData()
{
Console.WriteLine("The value 99999 in various formats:");
Console.WriteLine("c format: {O:c}", 99999);
Console.WriteLine("d9 Format: {O:d9}", 99999);
Console.WriteLine("f3 format: {O:f3}", 99999);
Console.WriteLine("n format: {O:n}", 99999);

// Notice that upper- or lowercasing for hex
// determines if letter are upper- or lowercase.
Console.WriteLine("E format: {O:E}", 99999);
Console.WriteLine("e format: {O:e}", 99999);
Console.WriteLine("X format: {O:X}", 99999);
Console.WriteLine("x format: {O:x}", 99999);
}
void DisplayMessage()
{
// Using string.Format() to format a string literal.
string userMessage = string.Format("100000 in hex is {O:x}", 100000);

// You would need to reference System.Windows.Forms.dll
// in order to compile this line of code!
System.Windows.Forms.MessageBox.Show(userMessage);
}
}
}
If anyone can help that would be great =D

i luffs yeww
04-06-2010, 01:43 PM
using System.Windows.Forms(.dll)? I don't know too much about C*, but why not add that? :p

XcanadamanX
04-06-2010, 02:10 PM
When i was using C# last semester we just called messagebox.show('blah'). but we didnt use console apps. try putting using System.Windows.Forms at the top with just messagebox.show

e: ok i just downloaded C# again and it seems that the console applications can not use System.Windows.Forms...

fronty
04-06-2010, 04:33 PM
Project -> Add Reference or do it via Solution explorer.

TRiLeZ
04-06-2010, 08:00 PM
using System.Windows.Forms;

...

MessageBox.Show(userMessage);

XcanadamanX
04-06-2010, 10:50 PM
Trilez: did you try that in a console application? because when i tried this morning, it gave me errors

P.S: it says you're a Senior SRL Meember :P

TRiLeZ
04-07-2010, 12:02 AM
P.S: it says you're a Senior SRL Meember :P

LOL, I wonder who changed that...

To solve the problem:

Project > Add Reference > .NET > System.Windows.Forms > OK

Then:


using System.Windows.Forms;

...

MessageBox.Show("Hello World");

Syronix
04-07-2010, 04:15 AM
Thx for the help compiled fine =D wooohooo