ā How do I get rid of 'System.ArgumentOutOfRangeException'
here the 'l'astname' substring doesnt come as output because of this exception can someone help me fix it?
28 Replies
Let's look at the docs (https://learn.microsoft.com/en-us/dotnet/api/system.string.substring?view=net-8.0#system-string-substring(system-int32-system-int32)):
public string Substring (int startIndex, int length);
length
Int32
The number of characters in the substring.
It's a length, not an end indexthat means if i write 7,12 it would work?
The lastname has only 5 characters
yeah
The counting feels confusing like
Is this an assignment?
no just me watching tutorials and doing random stuff
Because you could also just split at the white space (" ")
Which would work with every name
Assuming there is no middle name
i dont get it.....
Kinda like that
i dont know the split yet
so i was doing it with substring
C# Online Compiler | .NET Fiddle
Test your C# code online with .NET Fiddle code editor.
but i think i didnt get the full concept of substring right
Yeah, the 2nd parameter of
Substring(...)
is the length
Not an index
As canton7 pointed outoh i get it
so basically
the first nukbe ris starting point
Exactly
and second number is the lenght
I strongly recommend to add parameter hints here
Like the following
Makes it more readable
where do i find it?
The naming of the parameter hints has to follow the method signature
https://learn.microsoft.com/en-us/dotnet/api/system.string.substring?view=net-8.0#system-string-substring(system-int32-system-int32)
this pops out for me
You tried to create a substring which exceeds the boundaries of the string
yeah
ahh thx man
you helped me out
i appreciate it
You are welcome!
found the coding dictionary :D
Haha, exactly
Visual Studio should also be able to tell you the parameter names
C# holybook
Our bible
š