Reputation: 451
I have a stream reader object "file" and a character type variable "hex"
System.IO.StreamReader file = new System.IO.StreamReader(filename);
char[] hex=new char[20];
int @base;
the code i want to implement is
string line;
while ((line=file.ReadLine()) != null) //Reading each address from trace file
{
if (@base != 10)
{
line >> hex;
///this line giving errors, as shift right cannot be implemented on string types
address = changebase(hex, @base);
}
else
line >> address;
I am making a cache memory hit and miss project. But in c# shift right cannot be applied to string variables, so any other option to implement the line of code .. Please any help
Any other way to implement this line
Upvotes: 0
Views: 2018
Reputation: 437584
In C# you can only overload the operators <<
and >>
when one of the operands is an int
, so this type of code is strictly off limits.
User-defined types can overload the
>>
operator; the type of the first operand must be the user-defined type, and the type of the second operand must beint
. For more information, see operator.
The reason why you cannot do this is because the language designers did not want you to, and I certainly can't fault them. line >> hex
might look cool, but it does the same thing as line.Insert(hex)
and is usually much less descriptive of what actually happens.
Upvotes: 1