C # can also be used to perform vector operations, which solves a long-lasting doubt.
operator
structVector { Public Doublex, y, Z; PublicVector (DoubleXDoubleYDoublez) { This. x =x; This. y =y; This. z =Z; } Publicvector (vector rhs) { This. x =rhs.x; This. y =Rhs.y; This. z =rhs.z; } Public Override stringToString () {return "("+ x +","+ y +","+ z +")"; } Public StaticVectoroperator+(vector lhs, vector rhs) {vector result=NewVector (LHS); Result.x+=rhs.x; Result.y+=Rhs.y; Result.z+=rhs.z; returnresult; } Public StaticVectoroperator*(vector lhs, vector rhs) {vector result=NewVector (LHS); Result.x*=rhs.x; Result.y*=Rhs.y; Result.z*=rhs.z; returnresult; } }
Vector Vect1, Vect2, Vect3,vect4; Vect1=NewVector (3.0,3.0,1.0); Vect2=NewVector (2.0, -4.0, -4.0); Vect3= Vect1 +Vect2; Vect4= Vect1 *Vect2; Console.WriteLine ("vect1="+Vect1. ToString ()); Console.WriteLine ("vect2="+Vect2. ToString ()); Console.WriteLine ("vect3="+Vect3. ToString ()); Console.WriteLine ("vect4="+ Vect4. ToString ());
Output:
Reference: http://www.cnblogs.com/LilianChen/archive/2013/03/15/2961901.html
C # Implicit explicit keyword: http://www.cnblogs.com/chengxiaohui/articles/1914190.html
C # checked and unchecked usage: http://www.cnblogs.com/limingluzhu/archive/2011/11/07/2239130.html
Find doubts, doubts will eventually have to solve, just in that casual time, the next moment. So to believe, but also to believe that time will eventually give us the answer.
C # operator Notes