Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
Vectors2.cs
Package: CSharpprogramming.rar [view]
Upload User: lxycoco
Upload Date: 2022-07-21
Package Size: 38457k
Code Size: 2k
Category:
CSharp
Development Platform:
Others
- using System;
- namespace Wrox.ProCSharp.OOCSharp
- {
- struct Vector
- {
- public double x, y, z;
- public Vector(double x, double y, double z)
- {
- this.x = x;
- this.y = y;
- this.z = z;
- }
- public Vector(Vector rhs)
- {
- x = rhs.x;
- y = rhs.y;
- z = rhs.z;
- }
- public override string ToString()
- {
- return "( " + x + " , " + y + " , " + z + " )";
- }
- public static Vector operator + (Vector lhs, Vector rhs)
- {
- Vector result = new Vector(lhs);
- result.x += rhs.x;
- result.y += rhs.y;
- result.z += rhs.z;
- return result;
- }
- public static Vector operator * (double lhs, Vector rhs)
- {
- return new Vector(lhs*rhs.x, lhs*rhs.y, lhs*rhs.z);
- }
- public static Vector operator * (Vector lhs, double rhs)
- {
- return rhs*lhs;
- }
- public static double operator * (Vector lhs, Vector rhs)
- {
- return lhs.x*rhs.x + lhs.y+rhs.y + lhs.z*rhs.z;
- }
- static void Main()
- {
- // stuff to demonstrate arithmetic operations
- Vector vect1, vect2, vect3;
- vect1 = new Vector(1.0, 1.5, 2.0);
- vect2 = new Vector(0.0, 0.0, -10.0);
- vect3 = vect1 + vect2;
- Console.WriteLine("vect1 = " + vect1);
- Console.WriteLine("vect2 = " + vect2);
- Console.WriteLine("vect3 = vect1 + vect2 = " + vect3);
- Console.WriteLine("2*vect3 = " + 2*vect3);
- vect3 += vect2;
- Console.WriteLine("vect3+=vect2 gives " + vect3);
- vect3 = vect1*2;
- Console.WriteLine("Setting vect3=vect1*2 gives " + vect3);
- double dot = vect1*vect3;
- Console.WriteLine("vect1*vect3 = " + dot);
- }
- }
- }