An warware: sami harshen pc

Labarin game da yaren PC zai yi kama da haka:

Harshen kwamfuta shine kashin bayan zamani, duniyar dijital. Domin haษ“aka fahimtar wannan harshe, bari mu shiga zurfin zurfin duniyar shirye-shirye, musamman mai da hankali kan C#, yaren da ya dace da abin da Microsoft ya haษ“aka don dandalin .NET.

Kara karantawa

An warware: bazuwar int

Don kwatanta sarkar wannan, bari mu ษ—auki misali na samar da lambobi bazuwar a cikin C#.

A cikin shirye-shirye, ana amfani da lambobin bazuwar don dalilai daban-daban, daga gwajin damuwa zuwa wasanni da ayyukan kimiyya. A cikin C #, ajin Random yana ba da ayyuka don samar da lambobi bazuwar. ฦŠaukar wannan snippet code a matsayin misali:

Randomrand = sabon bazuwar ();
int randomNumber = rand.Next();

Lambar da ke sama za ta haifar da adadin bazuwar wanda zai iya zama ko'ina daga 0 zuwa Int32.MaxValue.

Fahimtar Random Class a C #

Ajin Random a cikin C # yana zaune a cikin tsarin sunaye kuma ya ฦ™unshi hanyoyi da yawa waษ—anda za a iya amfani da su don dalilai daban-daban. Don samar da adadin bazuwar, hanyoyin da aka fi amfani da su sune Next() da na gaba (Int32, Int32).

Na gaba (Int32, Int32) yana haifar da bazuwar lamba tsakanin ฦ™ayyadaddun lambobi biyu, yayin Na gaba() kawai yana haifar da bazuwar lamba tsakanin sifili da Int32.MaxValue.

Don ฦ™irฦ™irar misali na ajin Random, kawai yi amfani da layin lamba mai zuwa:

Randomrand = sabon bazuwar ();

Sa'an nan, don samar da bazuwar lamba:

int randomNumber = rand.Next(); // yana haifar da bazuwar lamba tsakanin 0 da Int32.MaxValue

Kara karantawa

An warware: Vector3.signedangle ba a nuna kusurwar waฦ™a a cikin haษ—in kai

Vectors kayan aiki ne mai ฦ™arfi a cikin shirye-shirye, musamman masu amfani wajen haษ“aka wasan. Suna iya wakiltar kwatance, saurin gudu, kuma a fili, matsayi a sararin 3D. Lokacin aiki tare da waษ—annan vectors, wani lokaci muna buฦ™atar ฦ™ididdige kusurwa tsakanin vector biyu. Wannan inda hanyar Haษ—in kai na Vector3.SignedAngle ya fara aiki.

Unity's Vector3.SignedAngle Hanyar tana ฦ™ididdige kwana a cikin digiri tsakanin filaye biyu dangane da shugabanci. ฦ˜imar sa yana daga -180 zuwa 180, don haka yana ba mu jagora kuma. Abin takaici, wasu masu amfani sun ba da rahoton al'amura tare da rashin nuna kusurwar da aka sanya hannu daidai. Bari mu shiga cikin hanyar da za ta iya magance wannan matsala ta gama gari.

Kara karantawa

An warware: kirtani yayi dai-dai da case

C # yare ne mai nau'i-nau'i da yawa tare da fasalulluka masu yawa waษ—anda ke sa ayyukan shirye-shirye su zama marasa ฦ™arfi. ฦŠayan irin wannan fasalin shine ikon kwatanta kirtani yayin yin watsi da rumbun su ta amfani da ฦ™ididdigar StringComparison. Ana amfani da aikin `string.Equals` don cimma wannan.

Kwatancen igiya yana da mahimmanci a yawancin yanayin shirye-shirye. Koyaya, sau da yawa, ba mu damu da batun rubutun da muke kwatantawa ba. C # yana sauฦ™aฦ™a wannan tsari ta amfani da aikin da ke cikin zuciyar ayyuka da yawa.

Kara karantawa

An warware: cire sau biyu

Tabbas, tabbas zan taimaka da hakan. A ฦ™asa akwai dalla-dalla daftarin jigon 'cire sau biyu a cikin C#'.

Harsunan shirye-shirye sun kasance kayan aiki mai mahimmanci don tsara duniyar fasahar mu. Wani takamaiman harshe wanda ya yi tasiri mai mahimmanci shine C #. An san shi don juzu'in sa da yanayin abokantaka mai amfani, yana ba da hanya madaidaiciya ga ฦ™alubalen coding da yawa. Matsala ษ—aya ta gama gari da aka warware ta amfani da C # ita ce rage sau biyu. ฦ˜aฦ™walwar da ke bayansa ita ce ฦ™ayyade bambanci tsakanin maki biyu na lokaci, ma'aunin da ke tabbatar da amfani a cikin daidaitawar taron, ฦ™ididdigar lokacin aiki, da rikodin nazari.

DateTime startTime = sabon DateTime (2022, 1, 1, 8, 0, 0);
DateTime ฦ™arshen lokaci = sabon Kwanan lokaci (2022, 1, 1, 10, 30, 0);
Bambancin TimeSpan = ฦ™arshenTime. Rage (startTime);

Lambar da ke sama tana wakiltar hanya mai sauฦ™i don ฦ™ididdige bambanci tsakanin sau biyu.

Kara karantawa

An warware: yadda ake share duk fayiloli a cikin kundin adireshi

Share fayiloli daga kundin adireshi aiki ne gama gari a cikin shirye-shirye masu alaฦ™a da tsarin. Waษ—annan ayyukan suna buฦ™atar kulawa da hankali, saboda rashin amfani da shi na iya haifar da asarar bayanai na dindindin. A cikin yaren shirye-shiryen C #, tsarin suna System.IO yana ba da hanyoyin yin irin waษ—annan ayyuka.

Kara karantawa

An warware: sami max enum ฦ™ima

Samun matsakaicin ฦ™ima daga nau'in ฦ™idayar aiki ne na gama gari wanda masu haษ“akawa ke ci karo da su. Ana buฦ™atar wannan a cikin yanayi inda kuke buฦ™atar tabbatar da shigarwar mai amfani ko sarrafa wasu albarkatu dangane da ฦ™imar ฦ™ima. C # yana ba da hanya madaidaiciya don cimma wannan ta amfani da ajin Enum da ษ—an ฦ™aramin LINQ.

Bari mu bincika mafita wanda ke sa maido da matsakaicin ฦ™imar ฦ™idayar da sauฦ™i kamar kek.

MyEnum na jama'a
{
Zabin1 = 1,
Zabin2 = 2,
Zabi3 = 3
}

...

jama'a int GetMaxEnumValue()
{
mayar da Enum.GetValues โ€‹โ€‹(nau'in (MyEnum)) .Cast().Max();
}

Wannan ษ—an gajeren lambar yana yin duk aikin maido da mafi girman ฦ™ima a cikin lissafin. Amma ta yaya yake aiki?

Zurfafa Shiga cikin Code

'Enum.GetValues(nau'in (MyEnum))' shine yanki na farko mai mahimmanci don fahimta. Wannan ginanniyar hanyar NET tana dawo da tsararru mai ษ—auke da ฦ™imar ma'auni a ฦ™ayyadadden ฦ™idayar. Ana wuce nau'in kirgawa azaman siga zuwa hanyar ta amfani da kalmar 'typeof'.

Da zarar muna da tsararru, muna buฦ™atar jefa shi zuwa lamba. Ana yin wannan ta amfani da .Cast() hanya wacce wani yanki ne na LINQ (Query Integrated Query). LINQ wani tsari ne na fasaha da hanyoyi a cikin .NET wanda ke ba mu damar yin aiki tare da bayanai ta hanyar da ta fi dacewa da sauฦ™i.

Bayan jefa ฦ™ima zuwa lamba, samun matsakaicin ฦ™imar yana da sauฦ™i kamar kiran hanyar .Max (), wani babban kayan aiki da LINQ ke bayarwa. Wannan hanyar tana dawo da matsakaicin ฦ™ima a cikin tarin ฦ™ima na int.

Amfani da Enum da LINQ Libraries

Ajin Enum wani yanki ne na tsarin sunaye a cikin NET kuma yana ba da hanyoyi da dama don aiki tare da ฦ™ididdiga. Wurin tafi-da-gidanka ne lokacin da kuke buฦ™atar yin kowane aiki mai alaฦ™a da nau'ikan enum.

A daya hannun, LINQ, wani ษ“angare na System.Linq namespace, yana daya daga cikin mafi iko fasali na C #. Yana ba da hanyoyi daban-daban don sarrafa tarin yadda ya kamata, kamar samun matsakaicin, ฦ™arami, ko matsakaicin ฦ™ima, rarrabuwa, da tace bayanai.

Kara karantawa

An warware: lissafi zuwa haske

Math na iya zama batun kalubale, amma tare da hanyar da ta dace, yana iya zama abin jin daษ—i da ฦ™warewa. Ga wasu shawarwari don taimaka muku farawa:

-Fara da koyon abubuwan yau da kullun. Sanin kanku da ainihin dabarun lissafi don ku sami tushe mai tushe wanda zaku gina shi.
- Yi amfani da albarkatun kan layi. Akwai albarkatu da yawa kyauta da ake samu akan layi waษ—anda zasu taimaka muku haษ“aka ฦ™warewar lissafin ku. Bincika gidajen yanar gizo kamar Khan Academy ko Dandalin Math don ฦ™arin taimako.
- Yi, aiki, yi! Yayin da kuke yin aiki, mafi kyawun za ku sami ilimin lissafi. Ku shiga cikin matsalolin ฦ™alubale kuma kuyi ฦ™oฦ™arin magance su da sauri. Wannan zai taimaka maka haษ“aka sauri da daidaito a cikin lissafin ku.
- Kasance cikin tsari. Ci gaba da bin diddigin ci gaban ku ta hanyar adana mujallar lissafi ko amfani da aikace-aikacen bin diddigi kamar Google Sheets ko Excel. Wannan zai taimake ka ka ci gaba da kasancewa kan ci gabanka da kuma bin diddigin duk wani cigaba da ka yi a kan lokaci.

An warware: madauki akan kaddarorin abu

Tsarin maimaita akan abubuwan abubuwa a cikin C # duka aiki ne na gama gari kuma ya zama dole, yana ba mu damar sarrafa bayanai masu ฦ™arfi kamar bayanan mai amfani, bayanan bayanan, da ฦ™ari. Yin maimaita ta waษ—annan yana nufin bi ta kowace kadarorin abu ษ—aya bayan ษ—aya, don aiwatar da wani aiki ko aiki.

A cikin C#, yaren da aka gina shi a kan manufar 'tsarin shirye-shirye masu dogaro da abu', muna da hanyoyi da yawa don cim ma wannan, tare da ษ—akunan karatu masu mahimmanci kamar Tunani. Laburaren Tunani yana ba mu damar bincika nau'ikan metadata da sarrafa abubuwa da ฦ™arfi.

Kara karantawa