So do i have to put
int between char’s and string’s?
So do i have to put
Look back 5 posts or so on this forum page – that might have what you’re looking for.
ty i got after 2 dayz
Well… then this course has a TON of bugs. I’ll report a bug using my ‘Get help’ button
What you are recommending is bad practice. Let’s take model building for example - inside your model your class properties will be specific data types since it makes a HUGE difference in processing speed and memory. Like why would you save someone’s name in a var when you know it will be a string? Or a birth date in a var when you know it will be a DateTime structure? It’s like someone tells you they need a tennis ball but you deliberately buy all types of ball there are. You waste money and storage cause of sheer laziness. Not to mention when your compiler starts to throw exceptions and you have every data declared as var XD I cannot stress how important it is to know with what type of data you are working with and how much easier it will make things for you and your team, if you ever work with one.
What bug are you experiencing?
I’m sorry, but in what reality does this exercise make any logical sense? Why would anyone write the first letter in the variable? What if the name was Steve Rogers or Banana Hammock King?
For the last part I skipped checking which position the last name started at and just wrote
string lastName = name.Substring(7);
Because we’re clearly not here to learn how to find things using C# only.
This made me feel stupid when I was clearly right in my thinking.
This is the I-don’t-know-how-many-th time that I’m here in the forums looking for answers because something in the C# exercises doesn’t make sense. I’m starting to think I may need to look elsewhere for a reliable way to learn C#, because I’m not sure I should trust what they’re teaching here, considering all the mistakes.
I will say that for declarations, I use plenty of applications where it’s good practice to declare types. It’s less and less common, but memory management is still pretty damned important in lots of applications.
This is my final attempt at this exercise, I continue to receive an error message that states that “charPosition” does not exist in this context. I’m following exactly what I’m being taught, what am I doing wrong?
// Get first letter int charPosition = name.IndexOf("F"); char firstLetter = name[charPositon];
Check your spelling.
I checked my spelling, I still get this: Program.cs(14,31): error CS0103: The name ‘charPositon’ does not exist in the current context [/home/ccuser/workspace/csharp-working-with-text-get-parts-of-strings/e7-workspace.csproj]
The build failed. Fix the build errors and run again.
Because it doesn’t exist, because what you defined an what you implemented is mismatched (spelling error).
Now I see, thank you so much! One last question: how is it that I can use the charPosition variable twice with it meaning two different things. For example, it asks me to extract the int of “F” with the charPosition variable, then it asks me to do the same for the last name Abbasi, using charPosition again, why is that?
I’m going to assume I correctly understood what your asking.
int charPosition = name.IndexOf("F");
This now exist. You declared an integer, an initialized it. Now, after this, you can do something like…
charPosition = name.IndexOf("H");
That same value charPosition now equates to this, not what you originally declared an initialized it with. Some data types are mutable, an others are immutable. This data type is mutable. Eventually you will hear talk about primitive data types, inferred, and many others but that’s getting ahead of things here. This link will go into detail about all that.
Types (C# Programming Guide)
Thank you for the reply, I understand a lot better now!
I have no idea what this is even asking me to do, or how it wants me to do it. It makes no sense to me.
I’ve been going along smoothly and I feel like I just hit a brick wall.