I really need help

Updated on December 28, 2017 in [A] C# .Net
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on November 17, 2017

Hello I’m pretty much new to C# ive been using C++ but im not good at C# at all… So I have this program to make : I gotta use array and methods. the array gotta be less than 50 or maximum 50 elements “for example it could be only 10” . Every element have to containĀ Name, surname and family name of female students. The program is to print the names of those who’s name ends with “a” and contain Chr in their name ! I would be soo happy and thankful if someone actually helps šŸ™‚ C# masters pls helpĀ 

  • Liked by
Reply
0 on December 28, 2017

1st. A string is a array of characters. You can therefor use stringName.Length.

Example: if (stringName.Length < 50 && stringName < 10) {Console.Write(“Your name is longer then 10 characters but shorter then 50”);}

Ā 

2nd. To find if the name contains Chr. You can use the Index of command.

stringName.IndexOf(“Chr”);

This gives you a value based on how many times “Chr” is used in the string. (this command is 0 based. So if their is no “Chr” it will return -1. You can therefor test if the IndexOf retunes -1.

Example: if (stringName.IndexOf(“Chr”) != -1) {Console.Write(“this name contains Chr”);}

3rd. As i said a string is array of characters therefor you can use a foreach command. I’m not a good programmer so this is a bit of a patchwork

example:

int _foreach = 0;

foreach(char c in stringName) {_foreach++; if (_foreach == stringName.Length && c == ‘a’) {Console.Write(“The string contains a ‘a’ in the end”);}}

Ā 

In the example I rund through all the characters in the string until i get to the last characters and then checks if it’s a ‘a’.

  • Liked by
Reply
Cancel