Is there a way to cast a string to an interpolation object?
example: $"{912+8/2}"
I've tried to put the raw text from my textbox into the interpolation $"{results.Text}"
(in the calculator you can type only numbers and .,/,*,-,+
).
Is there a way to let the system make the math?
/// <summary>
/// Logica di interazione per MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
//define onclick listener for the numbers
private void b0_Click(object sender, RoutedEventArgs e)
{
results.Text = results.Text + "0";
}
private void b1_Click(object sender, RoutedEventArgs e)
{
results.Text = results.Text + "1";
}
private void b2_Click(object sender, RoutedEventArgs e)
{
results.Text = results.Text + "2";
}
private void b3_Click(object sender, RoutedEventArgs e)
{
results.Text = results.Text + "3";
}
private void b4_Click(object sender, RoutedEventArgs e)
{
results.Text = results.Text + "4";
}
private void b5_Click(object sender, RoutedEventArgs e)
{
results.Text = results.Text + "5";
}
private void b6_Click(object sender, RoutedEventArgs e)
{
results.Text = results.Text + "6";
}
private void b7_Click(object sender, RoutedEventArgs e)
{
results.Text = results.Text + "7";
}
private void b8_Click(object sender, RoutedEventArgs e)
{
results.Text = results.Text + "8";
}
private void b9_Click(object sender, RoutedEventArgs e)
{
results.Text = results.Text + "9";
}
//define onclick listener for the operations and special char
private void ba_Click(object sender, RoutedEventArgs e)
{
results.Text = results.Text + "+";
}
private void bs_Click(object sender, RoutedEventArgs e)
{
results.Text = results.Text + "-";
}
private void bm_Click(object sender, RoutedEventArgs e)
{
results.Text = results.Text + "*";
}
private void bf_Click(object sender, RoutedEventArgs e)
{
results.Text = results.Text + "/";
}
private void bd_Click(object sender, RoutedEventArgs e)
{
results.Text = results.Text + ".";
}
private void bc_Click(object sender, RoutedEventArgs e)
{
results.Text = "";
}
private void be_Click(object sender, RoutedEventArgs e)
{
results.Text = $"{results.Text}"; //<-- Problem here
}
}