Click here to Skip to main content
15,890,345 members
Home / Discussions / C#
   

C#

 
GeneralRe: Is There An Incantation I'm supposed To Recite To Make The Data Appear? Pin
Roger Wright15-May-11 4:26
professionalRoger Wright15-May-11 4:26 
AnswerRe: Is There An Incantation I'm supposed To Recite To Make The Data Appear? Pin
OriginalGriff14-May-11 21:06
mveOriginalGriff14-May-11 21:06 
GeneralRe: Is There An Incantation I'm supposed To Recite To Make The Data Appear? Pin
#realJSOP15-May-11 0:32
mve#realJSOP15-May-11 0:32 
GeneralRe: Is There An Incantation I'm supposed To Recite To Make The Data Appear? Pin
Luc Pattyn15-May-11 2:34
sitebuilderLuc Pattyn15-May-11 2:34 
GeneralRe: Is There An Incantation I'm supposed To Recite To Make The Data Appear? Pin
Roger Wright15-May-11 4:39
professionalRoger Wright15-May-11 4:39 
GeneralRe: Is There An Incantation I'm supposed To Recite To Make The Data Appear? Pin
Roger Wright15-May-11 4:28
professionalRoger Wright15-May-11 4:28 
QuestionBeginner c# question Pin
SFORavi14-May-11 16:10
SFORavi14-May-11 16:10 
AnswerRe: Beginner c# question Pin
Luc Pattyn14-May-11 16:57
sitebuilderLuc Pattyn14-May-11 16:57 
Hi,

1.
welcome to CodeProject and to C#. I hope you have chosen a good introductory book and plan to study it front to back over time. In my opinion a book is the best way to get a consistent and global insight in a technology or language.

2.
please use PRE tags when showing a code snippet; either type them like so <PRE>my code</PRE> or use the "code block" widget above the text editor field. It will show formatted code, which is much more readable.

3.
The way you have organized the Temperature class, you need to create a Temperature object using the new keyword, then call its getCels() method, like so:
public static void Main(string[] args)
{
    for(int i=1; i<args.Length; i++) {  // skip args[0] as it contains the EXE path, not the optional parameters
        string fahrentheit=args[i];
        Temperature tempObject=new Temperature(fahrenheit);
        string celsius=tempObject.getCels();
        Console.WriteLine(fahrenheit+" F = "+celsius+" C");
    }
}

That should work, I haven't tested it, there may be a minor hickup somewhere.

4.
And then I have a lot of comments:

a) it is not so nice to have a Temperature constructor that takes a string as a parameter; "separation of concerns" would dictate that turning a string into a number is not a job for the Temperature class; likewise, getCels() should return a number, not a string.

b) the normal way to convert strings to numbers is by calling type.Parse() or better yet type.TryParse() where type is the type you want as a result.

c) when the Temperature class only serves a single purpose, it would be easier to just have a static method that takes a number of degrees Fahrenheit, and returns the equivalent number of degrees Celsius, like so:
public static float ToCelsius(float fahrenheit) {
    return ((fahrenheit-32.0f)*5.0f/9.0f);
}

That way, you don't need to create Temperature objects, you simply call the method:
float fahrentheit=float.Parse(args[i]);
float celsius=Temperature.ToCelsius(fahrenheit);
Console.WriteLine(fahrenheit.ToString()+" F = "+celsius.ToString()+" C");


d) please note I also used more appropriate variable and method names, more in line with C# tradition.

I hope this gets you going.

Smile | :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
modified on Saturday, May 14, 2011 11:17 PM

GeneralRe: Beginner c# question Pin
SFORavi14-May-11 18:34
SFORavi14-May-11 18:34 
AnswerRe: Beginner c# question Pin
Luc Pattyn14-May-11 18:39
sitebuilderLuc Pattyn14-May-11 18:39 
GeneralRe: Beginner c# question Pin
Roger Wright14-May-11 20:11
professionalRoger Wright14-May-11 20:11 
GeneralRe: Beginner c# question Pin
Richard MacCutchan14-May-11 21:32
mveRichard MacCutchan14-May-11 21:32 
AnswerRe: Beginner c# question Pin
PIEBALDconsult14-May-11 18:52
mvePIEBALDconsult14-May-11 18:52 
GeneralRe: Beginner c# question Pin
jschell16-May-11 8:37
jschell16-May-11 8:37 
AnswerRe: Beginner c# question Pin
jschell16-May-11 8:39
jschell16-May-11 8:39 
Questionhow to disable and enable network access with simple c# code Pin
MohammedMahmoud14-May-11 10:41
MohammedMahmoud14-May-11 10:41 
AnswerRe: how to disable and enable network access with simple c# code Pin
jschell14-May-11 11:31
jschell14-May-11 11:31 
GeneralRe: how to disable and enable network access with simple c# code Pin
MohammedMahmoud14-May-11 11:44
MohammedMahmoud14-May-11 11:44 
GeneralRe: how to disable and enable network access with simple c# code Pin
jschell16-May-11 8:29
jschell16-May-11 8:29 
AnswerRe: how to disable and enable network access with simple c# code Pin
Luc Pattyn14-May-11 12:11
sitebuilderLuc Pattyn14-May-11 12:11 
GeneralRe: how to disable and enable network access with simple c# code Pin
dybs17-May-11 16:11
dybs17-May-11 16:11 
AnswerRe: how to disable and enable network access with simple c# code Pin
Richard MacCutchan14-May-11 21:37
mveRichard MacCutchan14-May-11 21:37 
QuestionHow can my hosted asp.net website access my local machine database Pin
akosidandan14-May-11 2:15
akosidandan14-May-11 2:15 
AnswerRe: How can my hosted asp.net website access my local machine database Pin
Luc Pattyn14-May-11 2:45
sitebuilderLuc Pattyn14-May-11 2:45 
GeneralRe: How can my hosted asp.net website access my local machine database Pin
akosidandan14-May-11 3:28
akosidandan14-May-11 3:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.