Created
May 25, 2019 01:21
-
-
Save serdarsen/24272909595ac73b8ce47d1abf1cbf56 to your computer and use it in GitHub Desktop.
Double to string sample of vala : Calling a string property that contains "DoubleToString" result from base class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The code below can be run and test in https://tio.run/#vala | |
public class Vehicle | |
{ | |
public double Speed {get; set;} | |
public string SpeedText | |
{ | |
owned get{return DoubleToString(Speed, "%.0f");} | |
} | |
public Vehicle() | |
{ | |
} | |
protected string DoubleToString(double num, string format) | |
{ | |
char[] buf = new char[double.DTOSTR_BUF_SIZE]; | |
var str = num.format(buf, format); | |
return str; | |
} | |
} | |
public class Car : Vehicle | |
{ | |
public Car() | |
{ | |
} | |
} | |
public static int main(string[] args) | |
{ | |
var car = new Car(); | |
car.Speed = 1; | |
stdout.printf(car.SpeedText); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment