|
Oluwayomi wrote: I need a code snippet to triple numbers.
Oluwayomi wrote: MCP MCAD
And people ask me why I don't value certifications.....
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
here you go:
.<br />
.<br />
.<br />
number anyNumber;<br />
console.writeline("Computer...triple the number above or i will shoot");<br />
.<br />
.<br />
.<br />
.
My idea of ideal life : Eat, Sleep, Repeat
|
|
|
|
|
OK then. Here's a choice for you:
public int Triple(int value)
{
}
public long Triple(long value)
{
} .. and so on. Obviously you'll want to implement exception handling and validation to take care of those cases where the return values are outside min/max values. To call them you would do:
int value = Triple(10);
|
|
|
|
|
When you say "triple", do you mean:
1) Multiply it by 3
2) Multiply it by itself 3 times
3) Display it three times like "101010"
4) Chop off your neighbor's head and put it on a pike in your front yard
5) Post a programming question in the Lounge
6) Herd elephants to their doom
7) Offer a starving muslim a pork sandwich
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi,
You can use the following classes
public class Single
{
private int _iValue;
public int Value
{
get { return _iValue; }
}
public Single() : this(0) {}
public Single(int iValue)
{
_iValue = iValue;
}
};
public class Double
{
private int _iValue;
public int Value
{
get
{
Single sinA = new Single(_iValue);
Single sinB = new Single(_iValue);
return sinA.Value + sinB.Value;
}
}
public Double() : this(0) {}
public Double(int iValue)
{
_iValue = iValue;
}
};
public class Tripple
{
private int _iValue;
public int Value
{
get
{
Double douA = new Double(_iValue);
Single sinB = new Single(_iValue);
return douA.Value + sinB.Value;
}
}
public Tripple() : this(0) { }
public Tripple(int iValue)
{
_iValue = iValue;
}
};
You can use it like this;
Tripple tripNumber = new Tripple(5);
int iData = tripNumber.Value;
Learn from the mistakes of others, you may not live long enough to make them all yourself.
|
|
|
|
|
Great answer, but you have too much time on your hands!
|
|
|
|
|
J4amieC wrote: Great answer, but you have too much time on your hands!
This is not correct. If I would have too much time on my hands I would have come
with something Generic like this:
MultiType<Double, Double> mul4 = new MultiType<Double, Double>(5);
int iData = mul4.Value;
MultiType<Double, MultiType<Double, Single>> mul5 = new MultiType<Double, MultiType<Double, Single>>(5);
iData = mul5.Value;
And the classes:
public class Single
{
protected int _iValue;
public int Value
{
get { return Data(); }
}
public void setValue(int IValue)
{
_iValue = IValue;
}
protected virtual int Data()
{
return _iValue;
}
public Single() : this(0) {}
public Single(int iValue)
{
_iValue = iValue;
}
};
public class Null : Single
{
public Null() : this(0) { }
public Null(int iValue)
{
_iValue = 0;
}
protected override int Data()
{
return 0;
}
};
public class Double : Single
{
protected override int Data()
{
Single sinA = new Single(_iValue);
Single sinB = new Single(_iValue);
return sinA.Value + sinB.Value;
}
public Double() : this(0) {}
public Double(int iValue)
{
_iValue = iValue;
}
};
public class MultiType<TL, TR> : Single
where TL : Single, new()
where TR : Single, new()
{
public MultiType() : this(0) { }
public MultiType(int iValue)
{
_iValue = iValue;
}
protected override int Data()
{
Single baseLeft = new TL();
baseLeft.setValue(_iValue);
Single baseRight = new TR();
baseRight.setValue(_iValue);
return baseLeft.Value + baseRight.Value;
}
};
Learn from the mistakes of others, you may not live long enough to make them all yourself.
|
|
|
|
|
|
Learn from the mistakes of others, you may not live long enough to make them all yourself.
|
|
|
|
|
What about http://www.careerchange.com/[^]?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
I myself made an assembly (TripleMachine.dll) that I just import whenever I need to triple a number. It has support for multithreading, for when I need to tripple large chunks of data.
boolean dontNotCancel = ((!false && true) != (!true || false)) ? ((false == false || (true && (false == true ? true : false))) ? true : false) : (true != false && false);
|
|
|
|
|
hey, looks like my signature o.o
betonglasermur.FeedDwarf(pur_is, 17);
ProcessStartupInfo.AintNotCreateNoWindow = (false && !true) != (true || false) ? false == true ? true : false : (true != false && false);
Morgonen är tröttmans mecka
|
|
|
|
|
hey, that does not look like it isn't my signature
boolean dontNotCancel = ((!false && true) != (!true || false)) ? ((false == false || (true && (false == true ? true : false))) ? true : false) : (true != false && false);
|
|
|
|
|
|
I want to call cmd.exe from C# application and to change the directory from current directory.I have written code for this which is given below
------------------------------------------------------------------------------------------------------------------
//sample code //
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.ComponentModel;
namespace Console_sample
{
class Program
{
public void OpenWithArguments()
{
ProcessStartInfo startInfo = new ProcessStartInfo("CMD.exe");
Process p = new Process();
startInfo.RedirectStandardInput = true;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
p = Process.Start(startInfo);
p.StandardInput.WriteLine(@"Echo on");
p.StandardInput.WriteLine(@"dir " + @"C:");
p.StandardInput.WriteLine(@"chdir " + @"C:\WINDOWS ");
p.StandardInput.WriteLine(@"EXIT");
string output = p.StandardOutput.ReadToEnd();
string error = p.StandardError.ReadToEnd();
p.WaitForExit();
Console.Write(output);
p.Close();
Console.Read();
}
static void Main(string[] args)
{
Program myProcess = new Program();
myProcess.OpenWithArguments();
}
}
}
--------------------------------------------------------------------------------------
In the console I got following output
-----------------------------------------------------------------------------------------------------------
D:\Program\Console_sample\bin\Debug>Echo on
D:\Program\Console_sample\bin\Debug>dir C:
Volume in drive C has no label.
Volume Serial Number is F06C-447B
Directory of C:\Program Files\Microsoft Visual Studio 8\Common7\IDE
04/24/2008 05:17 PM <DIR> .
04/24/2008 05:17 PM <DIR> ..
03/26/2008 04:02 PM <DIR> 1033
D:\Program\Console_sample\bin\Debug>chdir C:\WINDOWS
D:\Program\Console_sample\bin\Debug>EXIT
---------------------------------------------------------------------------------
where my directory is not chaged while the DIR command got perfectly executed .How can i fix this ?Even i notice that when i write p.standardInput.writeline(@"date"); it doean't show me the date also.please provide solutuion for this .if anyone has sample code for executing cmd command from C# .net will be very useful.
any help appreciated
thanks in advance
|
|
|
|
|
The line you've written:
<br />
p.StandardInput.WriteLine(@"chdir " + @"C:\WINDOWS ");<br />
This will take effect:
<br />
p.StandardInput.WriteLine(@"chdir /d" + @"C:\WINDOWS ");<br />
|
|
|
|
|
Hey guys...
i have an console app that calls a different console app, im trying to get the result of the 2nd app printed in the 1st app.
heres my current code
Process myProcess = new Process();
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess = Process.Start("ring.exe");
Console.WriteLine("Started 1st process --> Waiting............ ");
myProcess.WaitForExit();
StreamReader sr = myProcess.StandardOutput;
Console.WriteLine("Finnished 1st process ---> output:");
Console.WriteLine(sr.ReadToEnd());
im getting the following error at runtime "StandardOut has not been redirected or the process hasn't started yet."
any ideas what im doing wrong?
thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
try this:
<br />
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd.exe");<br />
System.Diagnostics.Process p = new System.Diagnostics.Process();<br />
psi.RedirectStandardOutput = true;<br />
psi.UseShellExecute = false;<br />
p.StartInfo = psi;<br />
p.Start();<br />
p.WaitForExit();<br />
System.IO.StreamReader sr = p.StandardOutput;<br />
MessageBox.Show("Finnished 1st process ---> output:");<br />
MessageBox.Show(sr.ReadToEnd());<br />
|
|
|
|
|
i want to check through my C# code, Pen Drive Connect to computer yes or not only.
|
|
|
|
|
I don't think there's an event for that, but you CAN iterate over available drives and work out if any are removable. DriveInfo[] drives = DriveInfo.GetAllDrives() ( something like that ). Then, each one has an enum that tells you if it's a HDD, if it's optical, if it's removable.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
|
Hi,
Can someone try to tell me the definitive (like, yeah) way of sending a mail in c# from my website. I'm .NET2, Visual Sudio 2005 and have a 3 simple textboxs and a send button on my site for people to get in touch. I want it to send me the text1 as a subject, text2 as the body, text3 as their mail address (which they have manually typed in)
Obviously I've been round the web.....
private void Button1_Click(object sender, System.EventArgs e)
{
MailMessage mail = new MailMessage();
mail.To = txtTo.Text;
mail.From = txtFrom.Text;
mail.Subject = txtSubject.Text;
mail.Body = txtBody.Text;
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(mail);
}
these seem out of date, and how do I test locally on my machine? Do I put 'localhost' as my SMTP server? until it goes live?
Any help would be great.
Thanks
Harvey
|
|
|
|
|
imnotso# wrote: MailMessage mail = new MailMessage();
mail.To = txtTo.Text;
mail.From = txtFrom.Text;
mail.Subject = txtSubject.Text;
mail.Body = txtBody.Text;
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(mail);
This is obsolete now. Use classes in System.Net.Mail namespace. You can configure System.Net.Mail settings on the app.config file and put the server name as localhost . Stop local SMTP server and set mail delivery type as PickupDirectoryFromIis which will deliver mails to the pickup directory.
|
|
|
|
|
Thanks for that,
In the new classes I cannot find where I specify the SMTP server name. Any ideas?
Harvey
|
|
|
|
|
Plus 'localhost' always returns an error.
|
|
|
|