visual c sharp code example
Example 1: c#
/* Answer to: "c#" */
/*
C
encompassing strong typing, lexically scoped, imperative,
declarative, functional, generic, object-oriented, and
component-oriented programming disciplines.
*/
Example 2: visual c#
using System;
namespace Calculator
{
Example 3: visual c#
class Calculator
{
public static double DoOperation(double num1, double num2, string op)
{
double result = double.NaN; // Default value is "not-a-number" which we use if an operation, such as division, could result in an error.
// Use a switch statement to do the math.
switch (op)
{
case "a":
result = num1 + num2;
break;
case "s":
result = num1 - num2;
break;
case "m":
result = num1 * num2;
break;
case "d":
// Ask the user to enter a non-zero divisor.
if (num2 != 0)
{
result = num1 / num2;
}
break;
// Return text for an incorrect option entry.
default:
break;
}
return result;
}
}
Example 4: c#
double num = //some number you have
double num2 = //some another number you have
Console.WriteLine(num + num2);