Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unity subtract class

//Short Reference
public myClass{
public static myClass operator -(myClass instanceA, myClass instanceB){
//Do custom operation behaviour
return desiredValue;
}
}


//Example:
//To apply mathematical operators to instances of custom classes
//You need to do "Operator Overloading"
public Length{
//Our Length class is simply a length in inches and feet
public int feet;
public int inches;
//Constructor
public Length(int Feet, int Inches){
this.feet = Feet;
this.inches = Inches;
}
//we can declare our operator like a function, and identify it as an operator
//pass in 
public static Length operator +(Length l1, Length l2){
//for this example, we'll use a third instance to store the return data
Length l3 = new Length();
//subtract the feet and inches...
l3.inches = l1.inches-l2.inches;
l3.feet = l1.feet-l2.feet;
//and if the inches are negative, subtract from the feet...
if(l3.inches<0){
l3.feet--;
l3.inches += 12;
}
//then return it, just like a function
return l3;
}

}
Comment

PREVIOUS NEXT
Code Example
Csharp :: multi case in c# 
Csharp :: c# integer part of float 
Csharp :: how to fill model enum with bradio button asp razor 
Csharp :: administration 
Csharp :: change skybox color unity 
Csharp :: web client ignore ssl error 
Csharp :: oracle c# parameters wont work 
Csharp :: structure in c sharp with example 
Csharp :: c# enum to list of strings 
Csharp :: c# clear linkList 
Csharp :: c# convert excel column index to letter 
Csharp :: c# convert string to array 
Csharp :: raq query ef core 
Csharp :: how to set the current user httpcontext.current.user asp.net -mvc 
Csharp :: textbox gotfocus wpf 
Csharp :: c# response.contenttype set filename 
Csharp :: web.config customerrors not working 
Csharp :: run in wpf 
Csharp :: How to set default page asp.net MVC 
Csharp :: if or statement c# 
Csharp :: how to create class in c# 
Csharp :: c# list to observablecollection 
Csharp :: c# arrays 
Csharp :: datatable select c# 
Csharp :: string.format() c# 
Csharp :: how to add a ddos api to a c# console app 
Csharp :: c# int to short 
Csharp :: rename join ta le in many to many 
Csharp :: txt.att.net not working 2021 
Csharp :: unity transparent sprite 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =