|
Is some course just starting, or have you got this far before falling apart ?
You need to do your own homework, if we did it, how would that help you ?
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 )
|
|
|
|
|
Sure:
namespace Homework
{
public static class Math
{
[System.STAThreadAttribute()]
public static int
Main
(
string[] args
)
{
if ( args.Length > 1 )
{
System.Console.WriteLine ( DoMath ( args ) ) ;
}
return ( 0 ) ;
}
}
}
Now just write the DoMath method.
|
|
|
|
|
Now that was a brilliant take on how to answer a homework question... consider it stolen for future use!
Peter the small turnip
(1) It Has To Work. --RFC 1925[^]
|
|
|
|
|
|
I was wondering something...
Is it possible do do something like:
string s1 = "12345";
string s2 = s1.RemoveNum("5");
MessageBox.Show(s2);
Where further down you add the RemoveNum() method ONTO the string type?
something like...
public static string add RemoveNum(string num)
{
return string.Replace(num, "");
}
?
Just wondering...
-= Reelix =-
|
|
|
|
|
Why dont you just test this instead of wondering??
|
|
|
|
|
public static string add RemoveNum(string num)
{
return string.Replace(num, "");
}
obviously doesnt work (Seeing as I made it up on the spot :p)
Was googling around, and couldn't find anything particularly useful...
You can't override, since it doesnt exist...
I'm just wondering if there's a way TO do it
-= Reelix =-
|
|
|
|
|
OOP way to augment functionality is inheritance, but no luck this time: String class is sealed.
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
|
|
|
|
|
Dang :/
No evil way to hack through it? :p
-= Reelix =-
|
|
|
|
|
Of course there are ways, evil,
but you have to ask the devil.
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
|
|
|
|
|
*Decompiles the .NET Framework into Assembly*
*Inserts a new String Method*
*Recompiles*
*Looks Innocent*
*Thinks...*
Dang... Will only work on my PC
-= Reelix =-
|
|
|
|
|
check out extension methods
betonglasermur.FeedDwarf(pur_is, 17);
ProcessStartupInfo.AintNotCreateNoWindow = (false && !true) != (true || false) ? false == true ? true : false : (true != false && false);
Morgonen är tröttmans mecka
|
|
|
|
|
|
VICTORY!!!
using System;
class String
{
public string RemoveFirst(string num)
{
string toReturn = num.Remove(0, 1);
return toReturn;
}
}
class ExtMethodDemo
{
static void Main(string[] args)
{
String r1 = new String();
string r2 = r1.RemoveFirst("12345");
Console.WriteLine(r2);
Console.ReadLine();
}
}
Thanks laserbaronen!!!
-= Reelix =-
|
|
|
|
|
hmm o_o
public static class ExtMethods
{
public static string RemoveFirst(this string str)
{
return str.Remove(0,1);
}
}
class ExtMethodDemo
{
static void Main(string[] args)
{
string r1 = "12345".RemoveFirst();
Console.WriteLine(r1);
Console.ReadLine();
}
}
was thinking something like this
betonglasermur.FeedDwarf(pur_is, 17);
ProcessStartupInfo.AintNotCreateNoWindow = (false && !true) != (true || false) ? false == true ? true : false : (true != false && false);
Morgonen är tröttmans mecka
modified on Tuesday, May 20, 2008 10:05 AM
|
|
|
|
|
there is a way, using extension methods. but this requires c# 3.0 ..
Extension methods are static methods that can be invoked using instance method syntax. In effect, extension methods make it possible to extend existing types and constructed types with additional methods.
|
|
|
|
|
buchstaben wrote: In effect, extension methods make it possible
make it appear possible, when in fact it isn't.
|
|
|
|
|
PIEBALDconsult wrote: buchstaben wrote:
In effect, extension methods make it possible
make it appear possible, when in fact it isn't.
that's just what c# 3.0 specification says.
|
|
|
|
|
Hello everyone,
I understand there is no need to call Dispose explicitly when dealing with StreamReader/StreamWriter object instances since GC will take care of it in Finalizer method.
My question is, I want to know the benefits and potential issues of using "using" statement to deal with StreamReader/StreamWriter.
thanks in advance,
George
|
|
|
|
|
George_George wrote: I understand there is no need to call Dispose explicitly when dealing with StreamReader/StreamWriter object instances
you may not need to, but I would suggest its still good practice.
I always use using when dealing with stream readers/writers
using (StreamReader sr = new StreamReader(someStream))
{
...
}
|
|
|
|
|
Thanks J4amieC,
What is the benefit?
regards,
George
|
|
|
|
|
George_George wrote: What is the benefit?
Deterministic disposal. When the using statement ends, it will call Dispose(), it can reclaim the memory immediately and suppress GCs finalization.
|
|
|
|
|
|
Never leave it to the GC to take care of your cleanup. It is non-deterministic. You should take proper care to dispose of your resources.
The managed resource is automatically disposed when the control exits the using block, so you don't need to do it yourself. It is also disposed if your code exits abnormally (exception is thrown, etc).
Cheers,
Vikram.
The hands that help are holier than the lips that pray.
|
|
|
|
|
Thanks Vikram,
My current situation is, I am writing an Http Service and handle requests from client by using StreamReader in some function to read from InputStream of Http request.
My previous consideration is, even if GC is not worked determistic, or there will be exception, when the Http Service stops (process stops or terminations), all resources like native handle wrapped by StreamReader could be released automatically.
What is the benefit of using "using" statement?
regards,
George
|
|
|
|