|
thanks alot, infact i was afraid if the key for shared assembly can be installed with it (very funny).
thanks a lot.
Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|
Im not sure if i did the right thing to post here, i went through a few threads and i couldnt figure this thing out. sorry it's my first message, also im just learning c# and i have no idea wat error i have..
Should i post this somewhere else or create a message everytime?
This is my program:
using System;
class Work1
{
public static void Main()
{
int amount;
Console.WriteLine("Enter wage");
int wage = Console.ReadLine();
Console.WriteLine("Enter hours");
int hours = Console.ReadLine();
amount = (hours * wage);
Console.WriteLine("Amount = ", amount);
Console.ReadLine();
}
}
Im trying to learn c# and tried something very simple. wage*hours = my money. but of course i failed doing so.
Error 1 Cannot implicitly convert type 'string' to 'int' C:\Users\Saliba\Documents\Visual Studio 2008\Projects\Project2\Project2\Class1.cs 12 19 Project2
//refers to this line = int wage = Console.ReadLine();
Error 2 Cannot implicitly convert type 'string' to 'int' C:\Users\Saliba\Documents\Visual Studio 2008\Projects\Project2\Project2\Class1.cs 15 25 Project2
//refers to this line = int hours = Console.ReadLine();
those are the errors.
i know its pretty frustrating for admins and moderators to stay deleting/ moving posts. im sorry if this is the case.
thanks for future help, Luke
|
|
|
|
|
class Work1
{
public static void Main()
{
int amount;
Console.WriteLine("Enter wage");
int wage = int.Parse(Console.ReadLine());
Console.WriteLine("Enter hours");
int hours = int.Parse(Console.ReadLine());
amount = (hours * wage);
Console.WriteLine("Amount = {0}", amount);
Console.ReadLine();
}
}
|
|
|
|
|
Console.ReadLine() returns a string, which can't be automatically turned into an int. You'll need to use Int32.Parse() to do that (see msdn for more details and examples)
|
|
|
|
|
Hi,
welcome to CodeProject.
your post is OK, it is in the right place; no one is going to move or delete it, even when fully answered.
and neither should you, according to these guidelines[^]. The one thing you forgot to do is apply PRE tags to improve readability of your code snippet.
Your code shows two errors, you should take the error messages literally, they say "hey, here is a string and you want to treat it as an integer, I can't do that". And yes, that is what is going on as Console.ReadLine() returns a string, and you want to store it in an int.
This is a beginner's mistake; changing some type into some other type most often needs an explicit conversion; that could be either a cast (on inheritance up/downcasting), a call to a method of the Convert class (seldom really useful), or a call to a method of the destination's type class (most often).
So what you want here is int.Parse() with an explicit try-catch construct, or better yet int.TryPatse() Look those up in the MSDN documentation, make google your friend!
And if you aren't familiar with any of this, I strongly recommend buying and studying a book on C#. Here is
why[^].
Cheers.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
First of all just to let you know that console.ReadLine returns a string value so when it returns string value you can't directly assign it to and integer you should convert it to int
try
int x = Convert.toInt32(Console.ReadLine());
in console.WriteLine add the ".ToString()" so it would convert it to string so you could print it.
|
|
|
|
|
One more suggestion: tell your IDE to always show line numbers in editor windows; that way it is a lot easier to deal with compile-time and run-time errors. For Visual Studio look here[^].
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
As Luc said, you should probably use int.TryParse to check the input and convert the string input to an int.
You need some checking to deal with invalid input and re-request when necessary.
Console.WriteLine will automatically provide a string implementation of anything you supply by putting an index to it inside the string part in{} and placing the values as additional parameters.
Here's an ammended version of your code to explain by way of example:
int rate = 0;
int hours = 0;
while (rate == 0)
{
Console.Write("Enter rate: ");
if (!int.TryParse(Console.ReadLine(), out rate))
Console.WriteLine("Invalid input");
}
while (hours == 0)
{
Console.Write("Enter hours: ");
if (!int.TryParse(Console.ReadLine(), out hours))
Console.WriteLine("Invalid input");
}
int amount = (hours * rate);
Console.Clear();
Console.WriteLine("Rate = {0}, Hours = {1}{2}{2}Amount = {3}",
rate, hours, Environment.NewLine, amount);
Console.ReadLine();
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Thanks all for the great help. I made a copy with all the different versions you briefed me with. I feel like this is a good start and I can make it with people like you. Thanks, really. ^^
|
|
|
|
|
Hi,
I have a function which returns a byte array. This method is being called in a loop. I need to build another byte array from these returned byte array.
For eg., in StringBuilder, we can keep appending string to it. Similar way, i need to append byte array to one main byte array.
How can this be achieved? Can anyone give me some solution here?
Thanks for your time.
|
|
|
|
|
byte[] byteArray1 = new byte[10];
byte[] byteArray2 = new byte[10];
List<byte> byteList = new List<byte>(byteArray1);
byteList.AddRange(byteArray2);
byte[] byteArrayAll = byteList.ToArray();
|
|
|
|
|
Thanks this worked fine
|
|
|
|
|
Create new byte array ,which length is the sum of the source arrays lengths and use System.Array.Copy to copy source data to the result array.
Life is a stage and we are all actors!
|
|
|
|
|
Once an array's size is declared, it cannot be changed so you can't append directly to the end.
If you know the end size you need then you can declare a new byte array, and use Buffer.BlockCopy to copy from other arrays into the new one specifying offsets where needed etc.
If the end size is unknown, I'd use a List<byte> and use the Add method to copy a byte or AddRange to copy other byte arrays into it, then call ToArray on the List<byte> at the end, and you will then have an array of the correct size.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
I've been pondering on this a little more - these two methods may help. The first will append one or more individual items, the second one or more collections of items. These may not be the fatest, but they work.
public static T[] AddElements<T>(T[] currentArray, params T[] element)
{
T[] result = new T[currentArray.Length + element.Length];
Buffer.BlockCopy(currentArray, 0, result, 0, currentArray.Length);
for (int i = 0; i < element.Length; i++)
result[currentArray.Length + i] = element[i];
return result;
}
public static T[] AddElements<T>(T[] currentArray, params IEnumerable<T>[] elements)
{
List<T> resultList = new List<T>(currentArray);
foreach (IEnumerable<T> item in elements)
resultList.AddRange(item);
return resultList.ToArray();
} Some examples of useage:
byte[] currentArray = new byte[] { 0, 1, 2, 3, 4 };
byte elementA = 5;
byte elementB = 6;
byte elementC = 7;
currentArray = AddElements(currentArray, elementA);
currentArray = AddElements(currentArray, elementB, elementC);
byte[] elementsA = new byte[] { 8, 9, 10 };
byte[] elementsB = new byte[] { 11, 12, 13 };
List<byte> elementsC = new List<byte>() { 14, 15, 16 };
currentArray = AddElements(currentArray, elementsA);
currentArray = AddElements(currentArray, elementsB, elementsC);
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
modified on Wednesday, August 26, 2009 9:00 AM
|
|
|
|
|
Thanks for your reply
|
|
|
|
|
Hello
I need to view pictures of a file now this file has many pictures i need a way to access the first picture then navigate to the last one, the problem is that the images are not numeric named so i cant increment number to access the other image please help.
|
|
|
|
|
What have you tried?
What are they named?
Do you have an index of some sort?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
i am trying DirectoryInfo class to get the files inside of it in file info array then i would iterate around them but am facing problems you cant know what the names of the picture bcz it is the client's disicion and there is no index or sort.
|
|
|
|
|
Then you will have to sort them by name, or create date. If the user doesn't catch on fairly quickly that sequential naming is a good idea if you want to find things, then spell it out to him when he compains...
DirectoryInfo di = new DirectoryInfo(@"c:\XXTemp");
FileInfo[] fil = di.GetFiles();
is the way to go.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
string[] picFiles = Directory.GetFiles(@"D:\PICS");
foreach (string picFile in picFiles)
{
pictureBox1.Image = Image.FromFile(picFile);
MessageBox.Show("Press OK for next picture...");
}
The pictures are unsorted. If you don't have any index, then sort "picFiles" to date and time.
|
|
|
|
|
Hello, there is no need to put Bold on entire message. Your question conflicts with the title.
Are you looking for next image in same folder or are you looking how to get next frame in Animated Image (GIF)?
EDIT: I didn't saw other post, because my Firefox has cached and i saw old page.
You don't need to know names of file. You can actualy parse the order. You coud by Character code.
Also if you chose by date time, it desn't mean it will be accurate. If it was taken by camera, and you change batteries, there is possible date information could reset and new files coud have wrong DateTime
|
|
|
|
|
well guys my testing on directoryInfo have seeded now i got the names of the picture now all i have to do is to change from one pic to onther in a web form. could any body suggest how to make that happen i was thinking of making a panel that changes its directory by either clicking forward or backward but how i could change a paned directory is ther something as a panel directory?? Or how about an update panel inside it there is a picture were i assign the picture every time i click.?
|
|
|
|
|
My program is able to detect faces in pictures when these faces are closer to the camera view
however it is not able to detect faces which are furthur away from the camera (small faces E.g. picture of a Football Team)
I m using Emgu for the reference
Can any1 give some advice on this matter
|
|
|
|
|