| | |
error in c#
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2008
Posts: 20
Reputation:
Solved Threads: 0
namespace first
{
public class index
{
int count;
public index()
{
count = 0;
}
public static index operator++(index x)
{
x.count++;
return count;
}
}
class Program
{
static void Main(string[] args)
{
index i = new index();
i++;
Console.WriteLine(i);
}
}
}
when i am typing this program i got the error like.
first.index.operator++(first.index):not all code paths return a value;
{
public class index
{
int count;
public index()
{
count = 0;
}
public static index operator++(index x)
{
x.count++;
return count;
}
}
class Program
{
static void Main(string[] args)
{
index i = new index();
i++;
Console.WriteLine(i);
}
}
}
when i am typing this program i got the error like.
first.index.operator++(first.index):not all code paths return a value;
•
•
Join Date: Jan 2008
Posts: 2,052
Reputation:
Solved Threads: 120
Operator overloading is the least useful thing in C#, the operators are not any different than method calls, it is just good for mathematic obsessive people who like to use smybols rather than words to feel special as they are not valued when they go to techno bar to catch some chicks.
Due to lack of freedom of speech, i no longer post on this website.
•
•
Join Date: Jun 2009
Posts: 446
Reputation:
Solved Threads: 82
•
•
•
•
public static index operator++(index x)
{
x.count++;
return count;
}
C# Syntax (Toggle Plain Text)
public static index1 operator ++(index1 x) { x.count++; return x; }
Last edited by Ramesh S; Jul 20th, 2009 at 2:03 pm.
Operator overloads sure have their use. I don't see why you want to overload the C# ++ operator! It is there for your use! So use it as such, don't get fancy because you like to do it.
An index can easely be incremented with ++. Einstein once said: keep it simple, not simpler.
An index can easely be incremented with ++. Einstein once said: keep it simple, not simpler.
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: Jan 2008
Posts: 2,052
Reputation:
Solved Threads: 120
>keep it simple, not simpler.
that is what i told Scott just yesterday night
Einstein and i must think in paralel
But back to topic, even the + operator in math can be used with the Add name as a method. at compiler level each operator and function does the same thing. it is just for us, representation of that functionality is what changes.
what would you lose if you instead of int a = b + c use int a = Math.Add(b,c) ?
that is what i told Scott just yesterday night

Einstein and i must think in paralel

But back to topic, even the + operator in math can be used with the Add name as a method. at compiler level each operator and function does the same thing. it is just for us, representation of that functionality is what changes.
what would you lose if you instead of int a = b + c use int a = Math.Add(b,c) ?
Due to lack of freedom of speech, i no longer post on this website.
Serkan:
I think a=b+c is faster than a = Math.Add(b,c).
But for example the string class overloads the + operator to perform string concatenation. You could also use the Concat method for this, but a simple + is IMHO simpler. If you look in the produced IL code you would see that this + is translated into Concat by the C# compiler
Let the compiler worry about the gory details, that way you don't have to do that.
But you are right, most of the time we don't need operator overloading.
I think a=b+c is faster than a = Math.Add(b,c).
But for example the string class overloads the + operator to perform string concatenation. You could also use the Concat method for this, but a simple + is IMHO simpler. If you look in the produced IL code you would see that this + is translated into Concat by the C# compiler
Let the compiler worry about the gory details, that way you don't have to do that.But you are right, most of the time we don't need operator overloading.
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: Jan 2008
Posts: 2,052
Reputation:
Solved Threads: 120
i got what you mean, what i say is that "+" is a paradigm that we use for addition, to enable polimorphysm for addition they have the same operator concat strings when the type is string. It is our brain what makes the abstraction here, so instead of associating addition or concatenation with + sign, we could do it with a word "Add". the only problem would be of what data structure would this Add be part of. + does not belong to any class since it is an operator whereas Add is implemented inside different classes.
Due to lack of freedom of speech, i no longer post on this website.
Math.Add ??? Exists in Math class??! The answer shouldn't be to use it or not to use it.
Regardless this small operation in sometimes I shouldn't do that. Try we log error\exceptions
I can't permit developers team to do that
BUT, They must have method logs the error
Centralize operations important.
Again, regardless small adding operation mentioned above.
Regardless this small operation in sometimes I shouldn't do that. Try we log error\exceptions
I can't permit developers team to do that
C# Syntax (Toggle Plain Text)
try { } catch (Exception ex) { File.AppendAllText(ExceptionFilePath, ex.Message); }
C# Syntax (Toggle Plain Text)
try { } catch (Exception ex) { LogException(ex); } void LogException(Exception ex) { //Today DM (Development Manager) said we should use File //Yesterday they said we should log in database //tomorrow I think they aren't interested to know what exceptions happened }
Again, regardless small adding operation mentioned above.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
![]() |
Similar Threads
- Code 19 Registry Error (Windows NT / 2000 / XP)
- Error Loading operating System (Windows NT / 2000 / XP)
- svchost.exe error (Windows NT / 2000 / XP)
- New Hardware Causing Error (Windows NT / 2000 / XP)
- office 2000 install error (Windows NT / 2000 / XP)
- VMWare Unrecoverable Error (*nix Software)
- Error in Wrox Book (Perl)
Other Threads in the C# Forum
- Previous Thread: How do I point to data in my project?
- Next Thread: how to use paging in c#
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms function gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox pixelinversion post prime programming radians regex remote remoting resource 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







luckily does not exist...