शुरुआती के लिए विजुअल सी #। व्याख्यान 5. प्रकार रूपांतरण। गणना, संरचनाएं, सरणियाँ

सभी को नमस्कार!


अंत में, उन्होंने शुरुआती के लिए विज़ुअल सी # में पांचवां व्याख्यान लिखा। इस व्याख्यान में मैं आपको चर प्रकारों के रूपांतरण के बारे में बताऊंगा। तब आप गणना, संरचना और सरणियों के बारे में जानेंगे। बेशक, मैं व्याख्यान की कमी के लिए माफी माँगना चाहूंगा। यह इस तथ्य के कारण है कि मैंने अपने विश्वविद्यालय में Microsoft TechDays प्रौद्योगिकियों के दिन आयोजित किए और बिताए, और इस दिशा में काम करने के लिए बिल्कुल समय नहीं था। इसके अलावा, यह व्याख्यान इस वर्ष की आखिरी संभावना है! मुझे बहुत सारे हल किए गए काम मिले, जिसके लिए मैं उन सभी का बहुत आभारी हूं जिन्होंने भेजा और हल करने की कोशिश की। सही उत्तर, जो मुझे ई-मेल नहीं भेज सके, नीचे पोस्ट में हैं। साथ ही, व्याख्यान को रिकॉर्ड करने के लिए उपयोग किए जाने वाले स्रोत कोड को वीडियो के नीचे पाया जा सकता है।

पिछले व्याख्यान के लिंक

व्याख्यान 1. परिचय
व्याख्यान 2. नमस्कार, विश्व! और विज़ुअल सी # एक्सप्रेस 2010 को जानने के लिए
व्याख्यान 3. चर और भाव
व्याख्यान 4. शर्तें और चक्र

पिछले होमवर्क के जवाब:

1. यदि चर 2 और var2 में दो पूर्णांक संग्रहीत हैं, तो यह पता लगाने के लिए किस प्रकार की बूलियन जांच की जानी चाहिए कि क्या एक या दूसरे (लेकिन दोनों एक साथ नहीं) 10 से अधिक है?

(var1> 10) ^ (var2> 10)

2. एक एप्लिकेशन लिखें जो उपयोगकर्ता से दो नंबर प्राप्त करता है और उन्हें स्क्रीन पर प्रदर्शित करता है, लेकिन दोनों संख्याओं के 10 से अधिक होने पर विकल्पों को अस्वीकार कर देता है, और इस मामले में दो अन्य संख्याओं को दर्ज करने का सुझाव देता है।

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 .


3. निम्नलिखित कोड में क्या गलत है (विज़ुअल स्टूडियो का उपयोग किए बिना इस कार्य को हल करने का प्रयास करें)?
इसके बजाय "अगर ((मैं% 2) = 0)" होना चाहिए "अगर ((% 2) == 0)"

अच्छा दृश्य है!



व्याख्यान के सूत्र

प्रयोगशाला का काम नंबर १। रूपांतरण टाइप करें।
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 .


प्रयोगशाला का काम नंबर 2। लिस्टिंग।
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 .


प्रयोगशाला का काम नंबर 3। संरचना।
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 .


प्रयोगशाला संख्या 4। सरणी।
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 .


नया होमवर्क

1. परिचालन में से कौन सा नहीं किया जा सकता है:
a) संक्षेप में int
b) int में छोटा
c) स्ट्रिंग में बूल
डी) फ्लोट में बाइट

2. लिस्टिंग कोड के आधार पर एक कोड बनाएं जिसमें 4 अलग-अलग रंगों के रंग हों। क्या इस तरह की गणना बाइट पर आधारित हो सकती है?

3. निम्नलिखित कोड संकलित करेगा और क्यों?
string [] blab = new string [5]
string [5] = 5th string ;

* This source code was highlighted with Source Code Highlighter .


PS नया साल मुबारक हो, दोस्तों!
नए वीडियो की रिलीज़ के बारे में सबसे पहले जानने के लिए आप मेरे Vimeo चैनल को भी सब्सक्राइब कर सकते हैं।

Source: https://habr.com/ru/post/In109885/


All Articles