| | |
C# beginner need some pro advice
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
OK, but how would you have made a sub in vb, to send it say 2 parameters, and return the sum of them as a result?
(c# while different is not as hugely different in this respect)
(c# while different is not as hugely different in this respect)
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Perhaps it is something like this you want?
Will this clarify your mind?
Will this clarify your mind?
C# Syntax (Toggle Plain Text)
class Product { public string ReadName; //name of the product //other fields here public void ReadInput() { Console.Write(" Product name: "); string ReadName = Console.ReadLine(); //other things here } //other methods here } class MyConsoleApp { static void Main(string[] args) { Product objGet = new Product(); objGet.ReadInput(); //now here I can use Console.WriteLine("Name of product : {0}", objGet.ReadName); Console.ReadLine(); } }
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
•
•
Join Date: Feb 2008
Posts: 174
Reputation:
Solved Threads: 3
No errors, but no one of the public variables can be assigned to any values. No matter if I try to change data types. I dont know whats wrong. My code here should do a simple calculation and print out the results.
C# Syntax (Toggle Plain Text)
class Product { public string ReadName; //name of the product public double ReadPrice; //price of the product public int UnitCount; //Unit count public string FoodItem; //Unit count public void ReadInput() { Console.Write(" Product name: "); string ReadName = Console.ReadLine(); Console.Write(" Product price: "); double ReadPrice = Convert.ToDouble(Console.ReadLine()); Console.Write(" Unit count: "); int UnitCount = Convert.ToInt32(Console.ReadLine()); Console.Write(" Food item y/n: "); string FoodItem = Console.ReadLine(); } static void Main(string[] args) { Product objGet = new Product(); objGet.ReadInput(); double iPrice = objGet.ReadPrice; int iCount = objGet.UnitCount; double iCalc = iPrice * iCount; Console.Write(" Price total: {0}", iCalc); Console.ReadLine(); } }
Last edited by TobbeK; Jan 19th, 2009 at 3:07 pm.
That is totaly my fault! Not yours!
Can you see why?
I redefined ReadName as a local string variable of the method ReadInput!
Console.Write(" Product name: ");
string ReadName = Console.ReadLine();
should be
Console.Write(" Product name: ");
ReadName = Console.ReadLine();
do the same for the rest of your variables.
Sorry for the trouble, but do you know the definition of an expert?
An expert is a person who has made all the possible mistakes...
C# Syntax (Toggle Plain Text)
public void ReadInput() { Console.Write(" Product name: "); string ReadName = Console.ReadLine(); Console.Write(" Product price: "); double ReadPrice = Convert.ToDouble(Console.ReadLine()); Console.Write(" Unit count: "); int UnitCount = Convert.ToInt32(Console.ReadLine()); Console.Write(" Food item y/n: "); string FoodItem = Console.ReadLine(); }
I redefined ReadName as a local string variable of the method ReadInput!
Console.Write(" Product name: ");
string ReadName = Console.ReadLine();
should be
Console.Write(" Product name: ");
ReadName = Console.ReadLine();
do the same for the rest of your variables.
Sorry for the trouble, but do you know the definition of an expert?
An expert is a person who has made all the possible mistakes...
Last edited by ddanbe; Jan 19th, 2009 at 3:35 pm.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
![]() |
Similar Threads
- Softwares worth downloading (Windows NT / 2000 / XP)
- Windows XP Blackouts & Corrupt System32 - HELP PLEASE! (Windows NT / 2000 / XP)
- How to get started in IT? (IT Professionals' Lounge)
- Please review this -> (Website Reviews)
- YaBasic: The beginners choice (Computer Science)
Other Threads in the C# Forum
- Previous Thread: Reverse connection in C#
- Next Thread: incremental flag in C# 2.0 compiler
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox class client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum excel file files form format forms ftp function gdi+ image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






