Login Register






Beginner C# Question filter_list
Author
Message
Beginner C# Question #1
I was doing some research about the substring method when I saw these.
Ive seen them multiple times but never really know how they work.
Would someone mind explaining it to me or maybe telling me how this notation is called so I can do research on myself?
I would greatly appreciate it.

http://prntscr.com/wh4aha
(This post was last modified: 01-06-2021, 01:05 AM by Kostolany.)
Next Goal Gold!
[Image: giphy.gif]

Reply

RE: Beginner C# Question #2
(01-06-2021, 01:05 AM)Kostolany Wrote: I was doing some research about the substring method when I saw these.
Ive seen them multiple times but never really know how they work.
Would someone mind explaining it to me or maybe telling me how this notation is called so I can do research on myself?
I would greatly appreciate it.

http://prntscr.com/wh4aha
Substring basically takes whats inbetween the 2 ints you've given it on the string you want. For example lets use "Hello World", setting the starting index at 3 & the ending index at 7, the result will be "lo Wo", the result is whatever is inbetween the 2 indexes youve entered

Reply

RE: Beginner C# Question #3
(01-06-2021, 01:33 AM)miso Wrote:
(01-06-2021, 01:05 AM)Kostolany Wrote: I was doing some research about the substring method when I saw these.
Ive seen them multiple times but never really know how they work.
Would someone mind explaining it to me or maybe telling me how this notation is called so I can do research on myself?
I would greatly appreciate it.

http://prntscr.com/wh4aha
Substring basically takes whats inbetween the 2 ints you've given it on the string you want. For example lets use "Hello World", setting the starting index at 3 & the ending index at 7, the result will be "lo Wo", the result is whatever is inbetween the 2 indexes youve entered
Yes I am aware of that. Im sorry if I wasnt clear enough but my question was about the red underscored passages of the screenshot.
I know this notation:
Code:
Console.WriteLine($"{variable}");

But I have never heard of this one. Furthermore I dont know how this works, what the name of it is or even how to use it.

Code:
Console.WriteLine("{0} random filler string {1}");
Like used in the Screenshot. I hope this clears things up.
Next Goal Gold!
[Image: giphy.gif]

Reply

RE: Beginner C# Question #4
(01-06-2021, 01:40 AM)Kostolany Wrote:
(01-06-2021, 01:33 AM)miso Wrote:
(01-06-2021, 01:05 AM)Kostolany Wrote: I was doing some research about the substring method when I saw these.
Ive seen them multiple times but never really know how they work.
Would someone mind explaining it to me or maybe telling me how this notation is called so I can do research on myself?
I would greatly appreciate it.

http://prntscr.com/wh4aha
Substring basically takes whats inbetween the 2 ints you've given it on the string you want. For example lets use "Hello World", setting the starting index at 3 & the ending index at 7, the result will be "lo Wo", the result is whatever is inbetween the 2 indexes youve entered
Yes I am aware of that. Im sorry if I wasnt clear enough but my question was about the  red underscored passages of the screenshot.
I know this notation:
Code:
Console.WriteLine($"{variable}");

But I have never heard of this one. Furthermore I dont know how this works, what the name of it is or even how to use it.

Code:
Console.WriteLine("{0} random filler string {1}");
Like used in the Screenshot. I hope this clears things up.
idk i just use "aaaaa" & theThingIWantHere & "bbbb"

Reply

RE: Beginner C# Question #5
(01-06-2021, 01:40 AM)Kostolany Wrote:
(01-06-2021, 01:33 AM)miso Wrote:
(01-06-2021, 01:05 AM)Kostolany Wrote: I was doing some research about the substring method when I saw these.
Ive seen them multiple times but never really know how they work.
Would someone mind explaining it to me or maybe telling me how this notation is called so I can do research on myself?
I would greatly appreciate it.

http://prntscr.com/wh4aha
Substring basically takes whats inbetween the 2 ints you've given it on the string you want. For example lets use "Hello World", setting the starting index at 3 & the ending index at 7, the result will be "lo Wo", the result is whatever is inbetween the 2 indexes youve entered
Yes I am aware of that. Im sorry if I wasnt clear enough but my question was about the  red underscored passages of the screenshot.
I know this notation:
Code:
Console.WriteLine($"{variable}");

But I have never heard of this one. Furthermore I dont know how this works, what the name of it is or even how to use it.

Code:
Console.WriteLine("{0} random filler string {1}");
Like used in the Screenshot. I hope this clears things up.

In fact your question is not about substring, its about string formatting,
When you pass two or more argument to `Console.Write`, its automatically substitute the second parameter and upper values, inside the first parameter string "{0} random filler string {1}" by replacing the `{n} ` sub string with the n'th parameters passed to `Console.Write`.

for example :

Code:
String.Format("Name = {0}, hours = {1:hh}", name, DateTime.Now);

the result string will be the string `Name = {0}, hours = {1:hh}` where the {0} and {1} are replaced with the first parameter `name` and the second parameter `DateTime.now` values
`Name = fragx1011, hours = 21}`
its in fact a global approach used in many language for formatting string
you can google that : The .NET composite formatting
(This post was last modified: 01-07-2021, 09:06 PM by fragx1011.)

[+] 2 users Like fragx1011's post
Reply

RE: Beginner C# Question #6
(01-07-2021, 09:00 PM)fragx1011 Wrote:
(01-06-2021, 01:40 AM)Kostolany Wrote:
(01-06-2021, 01:33 AM)miso Wrote: Substring basically takes whats inbetween the 2 ints you've given it on the string you want. For example lets use "Hello World", setting the starting index at 3 & the ending index at 7, the result will be "lo Wo", the result is whatever is inbetween the 2 indexes youve entered
Yes I am aware of that. Im sorry if I wasnt clear enough but my question was about the  red underscored passages of the screenshot.
I know this notation:
Code:
Console.WriteLine($"{variable}");

But I have never heard of this one. Furthermore I dont know how this works, what the name of it is or even how to use it.

Code:
Console.WriteLine("{0} random filler string {1}");
Like used in the Screenshot. I hope this clears things up.

In fact your question is not about substring, its about string formatting,
When you pass two or more argument to `Console.Write`, its automatically substitute the second parameter and upper values, inside the first parameter string  "{0} random filler string {1}" by  replacing the `{n} `  sub string  with the n'th parameters passed to `Console.Write`.

for example :

Code:
String.Format("Name = {0}, hours = {1:hh}", name, DateTime.Now);

the result string will be the string `Name = {0}, hours = {1:hh}` where the {0} and {1} are replaced with the first parameter `name` and  the second parameter `DateTime.now` values
`Name = fragx1011, hours = 21}`
its in fact a global approach used in many language for formatting string
you can google that : The .NET composite formatting
Thank you for the answer. Is there any befefit to it?
Next Goal Gold!
[Image: giphy.gif]

Reply

RE: Beginner C# Question #7
(01-08-2021, 12:18 AM)Kostolany Wrote:
(01-07-2021, 09:00 PM)fragx1011 Wrote:
(01-06-2021, 01:40 AM)Kostolany Wrote: Yes I am aware of that. Im sorry if I wasnt clear enough but my question was about the  red underscored passages of the screenshot.
I know this notation:
Code:
Console.WriteLine($"{variable}");

But I have never heard of this one. Furthermore I dont know how this works, what the name of it is or even how to use it.

Code:
Console.WriteLine("{0} random filler string {1}");
Like used in the Screenshot. I hope this clears things up.

In fact your question is not about substring, its about string formatting,
When you pass two or more argument to `Console.Write`, its automatically substitute the second parameter and upper values, inside the first parameter string  "{0} random filler string {1}" by  replacing the `{n} `  sub string  with the n'th parameters passed to `Console.Write`.

for example :

Code:
String.Format("Name = {0}, hours = {1:hh}", name, DateTime.Now);

the result string will be the string `Name = {0}, hours = {1:hh}` where the {0} and {1} are replaced with the first parameter `name` and  the second parameter `DateTime.now` values
`Name = fragx1011, hours = 21}`
its in fact a global approach used in many language for formatting string
you can google that : The .NET composite formatting
Thank you for the answer. Is there any befefit to it?

To doing it that way? Not really. the whole string.format thing has largely been replaced by a different syntax.

Code:
int x = 5; // old way: string s = String.Format("{1} is an {2}", x, x.GetType()); // newer way: string s = $"{x} is an {x.GetType()}";

Hopefully that second one helps you better understand what's going on. Both of those options will produce a string of "5 is an int"

Reply

RE: Beginner C# Question #8
(01-10-2021, 07:07 PM)phyrrus9 Wrote:
(01-08-2021, 12:18 AM)Kostolany Wrote:
(01-07-2021, 09:00 PM)fragx1011 Wrote: In fact your question is not about substring, its about string formatting,
When you pass two or more argument to `Console.Write`, its automatically substitute the second parameter and upper values, inside the first parameter string  "{0} random filler string {1}" by  replacing the `{n} `  sub string  with the n'th parameters passed to `Console.Write`.

for example :

Code:
String.Format("Name = {0}, hours = {1:hh}", name, DateTime.Now);

the result string will be the string `Name = {0}, hours = {1:hh}` where the {0} and {1} are replaced with the first parameter `name` and  the second parameter `DateTime.now` values
`Name = fragx1011, hours = 21}`
its in fact a global approach used in many language for formatting string
you can google that : The .NET composite formatting
Thank you for the answer. Is there any befefit to it?

To doing it that way? Not really. the whole string.format thing has largely been replaced by a different syntax.

Code:
int x = 5; // old way: string s = String.Format("{1} is an {2}", x, x.GetType()); // newer way: string s = $"{x} is an {x.GetType()}";

Hopefully that second one helps you better understand what's going on. Both of those options will produce a string of "5 is an int"
yes I learned that second way at university
Next Goal Gold!
[Image: giphy.gif]

Reply