static void Main( string [] args)
{
double var1, var2;
Console .Write( "First: " ); Double.TryParse( Console .ReadLine(), out var1);
Console .Write( "Second: " ); Double.TryParse( Console .ReadLine(), out var2);
while (var1 > 10 && var2 > 10)
{
Console .WriteLine( "More than 10. Again." );
Console .Write( "First: " ); Double.TryParse( Console .ReadLine(), out var1);
Console .Write( "Second: " ); Double.TryParse( Console .ReadLine(), out var2);
}
Console .WriteLine( "First: {0}, second: {1}. Congrats!" , var1, var2);
Console .ReadKey();
}
* This source code was highlighted with Source Code Highlighter .
static void Main( string [] args)
{
short shortResult, shortVal = 4;
int integerVal = 67;
long longResult;
float floatVal = 10.5f;
double doubleResult, doubleVal = 99.999;
string stringResult, stringVal = "17" ;
bool boolVal = true ;
Console .WriteLine( "Variable Conversion Examples\n" );
doubleResult = floatVal*shortVal;
Console .WriteLine( "Implicit, -> double: {0} * {1} -> {2}" , floatVal, shortVal, doubleResult);
shortResult = ( short ) floatVal;
Console .WriteLine( "Explicit, -> short: {0} -> {1}" , floatVal, shortResult);
stringResult = Convert .ToString(boolVal) + Convert .ToString(doubleVal);
Console .WriteLine( "Explicit, -> string: \"{0}\" + \"{1}\" -> {2}" , boolVal, doubleVal, stringResult);
longResult = integerVal + Convert .ToInt64(stringVal);
Console .WriteLine( "Mixed, -> long: {0} + {1} -> {2}" , integerVal, stringVal, longResult);
Console .ReadKey();
}
* This source code was highlighted with Source Code Highlighter .
enum orientation : byte
{
north = 1,
south = 2,
east = 3,
west = 4
}
static void Main( string [] args)
{
byte directionByte;
string directionString;
orientation myDirection = orientation.north;
Console .WriteLine( "myDirection = {0}" , myDirection);
directionByte = ( byte ) myDirection;
directionString = Convert .ToString(myDirection);
Console .WriteLine( "byte equivalent = {0}" , directionByte);
Console .WriteLine( "string equivalent = {0}" , directionString);
Console .ReadKey();
}
* This source code was highlighted with Source Code Highlighter .
enum orientation : byte
{
north = 1,
south = 2,
east = 3,
west = 4
}
struct route
{
public orientation direction;
public double distance;
}
static void Main( string [] args)
{
route myRoute;
int myDirection = -1;
double myDistance;
Console .WriteLine( "1) North\n2) South\n3) East\n4) West" );
do
{
Console .WriteLine( "Select a direction:" );
myDirection = Convert .ToInt32( Console .ReadLine());
} while ((myDirection < 1) || (myDirection > 4));
Console .WriteLine( "Input a distance:" );
myDistance = Convert .ToDouble( Console .ReadLine());
myRoute.direction = (orientation) myDirection;
myRoute.distance = myDistance;
Console .WriteLine( "myRoute specifies a direction of {0} and a distance of {1}" ,
myRoute.direction, myRoute.distance);
Console .ReadKey();
}
* This source code was highlighted with Source Code Highlighter .
static void Main( string [] args)
{
string [] friendNames = { "Robert" , "Mike" , "Jeremy" };
Console .WriteLine( "Here are {0} of my friends:" , friendNames.Length);
foreach ( string friendName in friendNames)
{
Console .WriteLine(friendName);
}
Console .ReadKey();
}
* This source code was highlighted with Source Code Highlighter .
string [] blab = new string [5]
string [5] = 5th string ;
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/109885/
All Articles