- 6 hours ago
- #csharp
- #programming
- #coding
C# Programming For Beginners Lectures (3/14) will teach you #CSharp #programming from 0 to beginner / intermediate level. So if you have no idea about programming, if you don't know anything about #coding, or if you want to become a Software Engineer, please subscribe and follow our courses.
Discord ➡️ https://bit.ly/SECoursesDiscord
Patreon ➡️ https://www.patreon.com/SECourses
Technology Playlist (30+ Tutorial / Guide / News / Review Videos) ⤵️
https://www.youtube.com/playlist?list=PL_pbwdIyffsnkay6X91BWb9rrfLATUMr3
Stable Diffusion Playlist (30+ Tutorial / Guide Videos) ⤵️
https://www.youtube.com/playlist?list=PL_pbwdIyffsmclLl0O144nQRnezKlNdx3
Please join discord, mention me and ask me any questions. Thank you for like, subscribe, share and Patreon support. I am open to private consulting with Patreon subscription.
Full playlist of this course ⤵️
https://www.youtube.com/playlist?list=PL_pbwdIyffskoSXySh0MdiayPJsBZ7m2o
You can watch for free our C# Programming, ASP .NET Core MVC programming, Machine Learning and Software Engineering related courses on our playlists page ⤵️
https://www.youtube.com/@SECourses/playlists
GitHub code repository of this course (source codes of the lectures) ⤵️
https://github.com/FurkanGozukara/CSE105-2020-introduction-to-programming
Lecture 3/14:
* String Format, DatetTime, Format DateTime, DateTime.Add method
* How to debug line by line, step over, step into
* List Class, Index logic of arrays, lists, etc. in C#
* String Concatenation, String Manipulation
* Math.Round, Math.Floor, Numerics manipulation
* System Culture and System Culture Format and conversion affect
* How to use the If method
* Convert.To method usage
Topic 1: String Format, DateTime, Format DateTime, DateTime.Add method
Working with strings and dates is an essential part of programming, especially when it comes to C#. This language provides a set of tools that make it easier to format, manipulate and work with both strings and dates. In this article, we'll take a look at string format, DateTime, format DateTime and DateTime.Add method in C#.
String Format
The string format method allows you to format strings in a specific way. This method replaces the format items in a specified string with the string representations of corresponding objects. For example, you can use string format to format a date string in a specific way.
Here's an example:
csharp
Copy code
DateTime date = DateTime.Now;
string formattedDate = string.Format("Today is {0:dd/MM/yyyy}", date);
In this example, we are formatting the date string in the "dd/MM/yyyy" format. The "dd" is the day, "MM" is the month and "yyyy" is the year.
DateTime
DateTime is a class in C# that represents a date and time. You can use this class to create, manipulate and format dates and times. Here's an example:
csharp
Copy code
DateTime date = DateTime.Now;
This creates a new instance of the DateTime class with the current date and time.
Format DateTime
DateTime provides a method to forma
Discord ➡️ https://bit.ly/SECoursesDiscord
Patreon ➡️ https://www.patreon.com/SECourses
Technology Playlist (30+ Tutorial / Guide / News / Review Videos) ⤵️
https://www.youtube.com/playlist?list=PL_pbwdIyffsnkay6X91BWb9rrfLATUMr3
Stable Diffusion Playlist (30+ Tutorial / Guide Videos) ⤵️
https://www.youtube.com/playlist?list=PL_pbwdIyffsmclLl0O144nQRnezKlNdx3
Please join discord, mention me and ask me any questions. Thank you for like, subscribe, share and Patreon support. I am open to private consulting with Patreon subscription.
Full playlist of this course ⤵️
https://www.youtube.com/playlist?list=PL_pbwdIyffskoSXySh0MdiayPJsBZ7m2o
You can watch for free our C# Programming, ASP .NET Core MVC programming, Machine Learning and Software Engineering related courses on our playlists page ⤵️
https://www.youtube.com/@SECourses/playlists
GitHub code repository of this course (source codes of the lectures) ⤵️
https://github.com/FurkanGozukara/CSE105-2020-introduction-to-programming
Lecture 3/14:
* String Format, DatetTime, Format DateTime, DateTime.Add method
* How to debug line by line, step over, step into
* List Class, Index logic of arrays, lists, etc. in C#
* String Concatenation, String Manipulation
* Math.Round, Math.Floor, Numerics manipulation
* System Culture and System Culture Format and conversion affect
* How to use the If method
* Convert.To method usage
Topic 1: String Format, DateTime, Format DateTime, DateTime.Add method
Working with strings and dates is an essential part of programming, especially when it comes to C#. This language provides a set of tools that make it easier to format, manipulate and work with both strings and dates. In this article, we'll take a look at string format, DateTime, format DateTime and DateTime.Add method in C#.
String Format
The string format method allows you to format strings in a specific way. This method replaces the format items in a specified string with the string representations of corresponding objects. For example, you can use string format to format a date string in a specific way.
Here's an example:
csharp
Copy code
DateTime date = DateTime.Now;
string formattedDate = string.Format("Today is {0:dd/MM/yyyy}", date);
In this example, we are formatting the date string in the "dd/MM/yyyy" format. The "dd" is the day, "MM" is the month and "yyyy" is the year.
DateTime
DateTime is a class in C# that represents a date and time. You can use this class to create, manipulate and format dates and times. Here's an example:
csharp
Copy code
DateTime date = DateTime.Now;
This creates a new instance of the DateTime class with the current date and time.
Format DateTime
DateTime provides a method to forma
Transcript
00:00:00Hello dear students. Welcome to the lecture 3 of Introduction to Programming course. I'm going to compose a new console
00:00:08application and start the lecture. Create new project. Okay, consoleapp.net core. Okay, let's select the folder. It will be
00:00:29in. Alright. Okay, I hope you have watched carefully the previous lecture.
00:01:03Because it was really important. And let's check what we have done in the previous lecture. Okay, this is the
00:01:13source code of the previous lecture. We have shown string datatype, bool datatype, character datatype, deciml, double, float, integer, numerics.
00:01:27And what those numerics means. Their ranges.
00:01:34Some string format and such. So we will start writing our methods which is extremely important. In object oriented programming
00:01:56programs are composed by classes and methods mostly. So to do tasks.
00:02:08We need methods. To achieve things we need methods. For example, in this code currently there is a one method.
00:02:19Which one is it? Yes, it is the method of main. Okay. So this is a method. It is a
00:02:28static method. We will see that in future. It returns nothing because its returning parameter is void. Its name is
00:02:37main.
00:02:38It takes some arguments which is a string array in this case. And it does, it executes this line. Okay.
00:02:49So, I will write a method that will format my string and return me that string. So, first I have
00:03:05to determine its accessibility. It can be private.
00:03:11It can be public. It can be protected. Okay. By default, they are private. We will see what they mean
00:03:20in future. I am writing currently default and private. Will it return anything or not? It can be static or
00:03:35non-static. I am writing static. So we'll see what does that mean in future.
00:03:42String and the method name. Okay. So the method name will be return me date. So will it take any
00:03:56parameters? Let's get the date. Okay. DateTime. MyDateTime. Okay. And I want it to format the output as I want.
00:04:16Okay, so I'm going to write here string date format. Okay, so this is the first private part. Private means
00:04:29is accessibility level. Okay, so private means that only methods inside the parent class of this method can access this
00:04:42method.
00:04:44So the parent of this method, the parent class of this method is class program. So all the classes inside
00:04:52class program or methods inside class program can access this method. However, other methods or let's say the methods other
00:05:06than in this class cannot access it. So private means its accessibility level.
00:05:12Static means that it is initialized when the first time followed. So maybe there is a better explanation than this.
00:05:34You will have better idea. Let's see if there is a good description. Okay, so this description is not bad.
00:06:19I will get it read.
00:06:25And as we use it, you will understand at the moment. Don't be upset. Static, in C Sharp, is a
00:06:44keyword that can be used to declare a member of a type so that it is specific to that type.
00:06:49The static modifier can be used with a class, field, method, property, operator, event, or constructor. A static member of
00:06:58a class can be used to keep track of the instances created and maintain common data to be shared among
00:07:04all instances.
00:07:05It can be used in helper and utility classes, which usually contain generic methods that contain abstractions of pure logic.
00:07:13A static constructor is used to make entries in log files, as well as in wrapper class to load the
00:07:19dynamic link libraries required to execute unmanaged code. In general, a static modifier can be used with data and functions
00:07:29that do not require an instance of a class to be accessed.
00:07:33It is mostly used when the data and behavior of a class do not depend on object identity. The use
00:07:40of static classes and members improves code efficiency. So actually this is the important part. Let's read it again and
00:07:47you will understand in future better. In general, a static modifier can be used with data and functions that do
00:07:56not require an instance of a class to be accessed.
00:07:59It is mostly used when the data and behavior of a class do not depend on object identity. The use
00:08:06of static classes and members improves code efficiency. OK, so I will copy paste this description. Yes, OK. Oh, it
00:08:24is. Now I have made it a comment. And the string. String means that.
00:08:35The method will return an object in string type. So this is accessibility level. This is the modifier. And this
00:08:49is the parameter type. Data type that it will return. Okay. Return. Return date time. Or return formatted date time.
00:09:06And this is the name of the method. It has to be unique within the signature of what it takes.
00:09:15We will see signature of methods in future. So after I have typed the method name. I open a parenthesis
00:09:23and close it. This is mandatory for all methods. Because every method starts with a parenthesis and it is closed.
00:09:36Paranthesis you define whether it takes any data or not. This method takes an object with the data datetime type.
00:09:47Okay. Datetime is a struct type. We will see that in future. And an object with a string type. String
00:09:54is a class. And what will it do? It will return string.format.
00:10:07The object will be datetimeNav. Date. There is no number. So it is returning a string currently with formatting it
00:10:29the format I provide. So let's see datetime format C sharp and let's do some formatting.
00:10:47Okay, so this is the way we format the date. Okay, string format. Okay, there are the patterns. Oh, these
00:11:11are the quick patterns. t, d, t and such. So let's start with a short date time pattern. What I'm
00:11:25going to do is short date.
00:11:35I'm going to put a tab character. And then I'm going to add. I'm going to call my method. How
00:11:44do I call it? I type its name. Or let's make it easier for you. It's below. So this line
00:11:54will be written. Printed on the screen. And I will call my method. And I will provide date time now.
00:12:03DateTimeNow is a read on the struct object. This will provide the date time of that particular movement that the
00:12:18method is called. Okay. Or I can make it like this. Compose dateTime by date equal to dateTimeNow.
00:12:33This will contain the date of this line executed. Whenever this line is executed in the software, in the program,
00:12:41it will get that moment's date based on my local time. And then I will provide the data which will
00:12:50be my date and the string format. So format will be like this. So what does this mean?
00:13:05Means that when you call string format, it will look for the first parameter. And the first parameter will be
00:13:15here this one. This will be the first parameter you can see. You see it says object argument zero. It
00:13:26can be argument or it can be arguments array. It can take one argument, two argument, three argument, whatever you
00:13:33want.
00:13:34So we are providing only one argument and it will be the first argument. Its index will be zero. Okay.
00:13:47So when I call this, it will return me a string. So I will console right line A. So this
00:14:11is also a method. A method inside console class. And it returns nothing. You see it is void. Because it
00:14:19is printing.
00:14:20The value on the console and I'm running application. Okay, short date time pattern is below. It is 12 AM.
00:14:39So it only shows the hour of the date and doesn't show the minute. You can see that hour minute
00:14:49pt. Okay, so short date will return.
00:14:56Based on the US culture currently because my date is that way. Okay, I have provided TT and I should
00:15:09have provided T I guess. I have provided T. This is interesting. Okay, let's provide another one. What I'm going
00:15:34to do is copy paste and what other there is D.
00:15:50It is short time. This was short time. And this will be long time. I will provide big time. And
00:16:09currently, this gives an error. Why? Because it says a local variable or function name it. We are formatted string
00:16:17is already defined. Yes, we have defined it here. So you cannot define it again. However, when I remove this,
00:16:24this will get a new.
00:16:27Value on this line. So the previous value will be lost. And it will get a new value here. New
00:16:33assignment. And it will print the new value here. So in C sharp. The program is executed from top to
00:16:41bottom. First it starts from here. It executes this line. Then it executes this line. And then it executes this
00:16:49line. And this line. You see each one is line by line executed.
00:16:56Let's take some nodes. Okay, so how do we debug the application? You see it is currently running in debug.
00:17:44Debug will be your best friend to find where there are errors. So to debug the application, I can put
00:17:53here a breakpoint with just clicking. I can hit F9 on my keyboard.
00:18:04Where my cursor is located. And you can come here. And you can click the toggle breakpoint. Okay. All these
00:18:14three methods works. So I have put here a breakpoint. When I run the application. It will execute the software
00:18:21until deadline. And then I can continue. So I will continue with step over. So I have step it over.
00:18:29Let's run again. So currently.
00:18:34The application is paused at this line. When I hover the object it will show me its value. Currently date
00:18:45time is set to 1 1 1 12 am. So it is set to year one. Because it is not
00:18:55yet assigned to this value. It will be assigned to this value after I execute this line.
00:19:06You see the now value is updated every time when I hover it because it is dynamic. I click the
00:19:13step over and now my date is set. Okay, it won't change again. And so currently on the screen there
00:19:23is nothing and after this line is executed. It will call the right line method of console class and it
00:19:30will print this to the screen. I'm going to step over. Okay, it is also executed now.
00:19:36And when I click console, I see it is executed. And when I click next, I see this is composed
00:19:45from my datetime. And when I click the next line, I see it is printed on the screen. I will
00:19:55see. Okay, there is a bug in the Microsoft Visual Studio. This sometimes happens. So I will put my breakpoint
00:20:07here this time. And you will see it on the screen.
00:20:15Oh, I need to close this first. Okay. Okay, you see it is all printed on the screen. So when
00:20:26I go to next step. Okay, I have error again. I will use another method. Okay, so to go here,
00:20:47I will click this. It will continue until that time on here. Okay, long pattern. And when I continue with
00:20:56step over. Okay, so the long date is 12 a.m.
00:21:02However, still there is a problem. And I know that problem. To solve that problem, I will go into this
00:21:11function. How will I do that? I'm clicking here a breakpoint. Running the application. And this time I will click.
00:21:27First I need to close this and run again.
00:21:32I will click Step Into instead of Step Over. Step Over means it jumps over that method and continues within
00:21:41that class. However, if you click Step Into, it will enter this method. Okay. And I will click Step Into.
00:21:49So you see it has entered this method called. And I'm continuing with Step Over. And this is providing date.
00:21:58You see date is provided as this.
00:22:01Okay, so you see the minute is removed from the date. So what do I need to provide? I need
00:22:11to provide. Okay, I will provide nothing. I will provide as a full date type object. This time it should
00:22:24be the minute of the date as well. Okay, yes. Now it shows long time pattern, short time pattern.
00:22:37Okay, so I will make another example of string format. Let's say you have five names. I'm going to compose
00:22:50a list called this name string. So we are going to see the list class. So list is there as
00:23:23from name it indicates represents a strongly typed list of objects that can be accessed by index.
00:23:32Provide methods to search, sort, and manipulate lists. So first generic name is list. List is a class SystemCollections generic
00:23:42list. And then I define the data type it will hold. This list will hold string data type. When I
00:23:54do like this, it will not work. Because since this is a class, I have to initialize it.
00:24:01Okay. And this is not a static. Even if it was static, I had to still initialize. To initialize this,
00:24:08I have to use this. New keyword is used to initialize. And it automatically tells that you should use this.
00:24:21And I am going to initialize it like this. So I have initialized an empty list here.
00:24:30Let me show you what I mean. I am putting here a breakpoint and I am running the application. So
00:24:37when I hover LST my list, you see it shows null. Because it is still not initialized. It is just
00:24:47an abstract at the moment. And when the object is null, it means that it is not initialized. And when
00:24:53I go to the next line, you will see it is initialized as an empty list. I'm going to next
00:24:59line. And when I hover, you see.
00:25:01It is count zero because it is not anymore null and it is initialized. Then I will add some objects
00:25:11to it. Let's add my name. You see add method is a method of list class. And it takes a
00:25:27string item. In this case because my list is string type. Holding string data type. To string I open double
00:25:37quotas.
00:25:39My name, my surname, my email. Okay, so I am going to print this to the screen with string format.
00:26:09I'm going to do the console right line. See right line writes a line and a new line. Okay, I
00:26:17see current line terminator to the standard output stream. It supports string format by default if you want. You see
00:26:30string format and objects.
00:26:32So I am going to use that way and other way. So it will be this first object zero index.
00:27:00So these are the elements indexes. Indexes always start from zero. Okay, one second. I will pause for a moment.
00:27:31Okay, so indexes always start from zero. So this will print.
00:27:40The objects to the screen currently really work. Let's try it. Okay, it just printed this as a string. Why?
00:27:54Because currently this signature is only a one string. So the write line method sees this as a string value.
00:28:05However, when I start providing objects, you see it already shows object argument zero.
00:28:14Call this method override. So I am providing first value of my list. How do I do that? I type
00:28:24the list name and I open square parentheses. Why I can't open it? My language changed. Okay. Okay. You see
00:28:42square brackets used to access index of access 13.
00:28:50Indexed elements of arrays list. So my first name is this one. And when I run it, will it work?
00:29:06Okay. Now it has caused an exception. Unhandled exception. Why is that? Because now it will assume me that I
00:29:21will provide at least
00:29:24Because there is zero index-based object, index one object and index two object. So I have to provide at
00:29:35least three objects and I'm going to provide them. First one, second one and the third one. So this will
00:29:48get the first element in my list. This will get the second element in my list. And this will get
00:29:54the third element in my list.
00:29:56I call it. Okay. My name is Furkan. My surname is Gözükara. My email is. Email is. You see I
00:30:06have double typed it. This one. Okay. So now it works. I can write this like this as well. So
00:30:17you will get the idea. Let's compose the string. I will call the format. And the format will be this
00:30:36and the object. I can provide extra.
00:30:43As long as I provide the number of necessary objects here. So let's add another thing to my list. And
00:31:00I will provide Toros University as well here. Will this work? Yes, definitely. Because it will require me to provide
00:31:08three objects.
00:31:12It will be providing four objects. However, it will use only the first three ones. And I will make it
00:31:24like this. First way and second with the top character. I will get more understanding. Okay, first way, second way
00:31:56you see. They are both identical at the moment. Both works. The string format.
00:32:27Okay, so I will show you another thing. Let's say this time my school is 3. So what will this
00:32:51do? What will this print? This will print like this. My school is Toros University. You see that? How did
00:33:07it happen? It happened this way.
00:33:15Fourth parameter. Third index means the fourth parameter in the argument list. What is the fourth parameter in the argument
00:33:23list? It is this one. Because this is the first parameter in the argument list. This is the second parameter
00:33:29in the argument list. This is the third parameter in the argument list. And this is the fourth parameter in
00:33:34the argument list. So don't get confused with these numbers. These numbers means that it will take the.
00:33:43That index from that list. Not related to this. This will look to provided arguments. Let's make another example so
00:33:52you will understand. I'm just co-pasting. Fourth way. Zero. And I'm going to delete other ones. So I will
00:34:06just provide zero here. The school variable here. What will this print do you think? To the screen. It will
00:34:18print this. You see.
00:34:26Let's fix this one. For you it is printing only my school is Toros University. Because it is looking the
00:34:44first provided argument which is this one. And this one is the fourth element of the list. I am going
00:34:52to put a breakpoint here so you can hover over the list and see its items. So you see the
00:34:59first item the zero Bayezid index is Furkan.
00:35:03The second item, the one-based index is Gözükara. The third item, the two-based index is MyEmail. And the
00:35:11third one, the fourth element of the list, it is based on three index is Toros University. Okay. So I
00:35:22will show you another one. Let's say fifth way. My zero and zero.
00:35:44I will put here zero. So this will use the first provided object twice times, double times. Okay. Or I
00:35:58can make it and let's type my school name. So this will be the second provided parameters. And as a
00:36:19second parameter, I will provide the school name.
00:36:27To the screen, you will understand it. Okay, my name twice times is Furkan, Furkan UC. And my school name
00:36:39three times is Toros University, Toros University, Toros University. You can change this font size from right click, edit, properties,
00:36:52font size. For example, let's make it 20.
00:36:57So you see now it is 20 font size and I can see more. I'll make it a little bit
00:37:04bigger again. Okay, so let's make it a little bit smaller. Okay, so this means each time the string format
00:37:24method sees this, it will write the first argument.
00:37:33I can write it like this as well. This is the feature of C-Sharp 6 and above. So if
00:37:39you are working with various versions of .NET, it won't work. I will make it like this. Inline commenting. I'm
00:37:51going to lower it. You see this will be harder. I am putting a dollar sign in front of it.
00:37:59Now these became variables. For this variable, I will type like this.
00:38:12This will be same. So this is inline parameterization. I don't know, maybe something else it is called. And this
00:38:26will be this. When I type it, you will see it. I run it. Okay, it is working. However, this
00:38:39is, you see, harder to write. And you can also write it like this. This is string concatenation.
00:38:49You will see how bad it looks. It's plus. And then like this. And this is regular string concatenation. And
00:39:14plus. You see this is much harder to write. Looks bad. Plus. This is the seventh way. Which I made
00:39:43a mistake here. And when I click, I am pressing hold the control button.
00:39:50P and D keywords, it automatically formats my screen. You see. Auto format code shortcut in Visual Studio. Format document,
00:40:32Control plus K, Control plus D. So type Control plus K and then Control plus D as it is a
00:40:38sequence. Format selection, Control plus K, Control plus F. OK, so you know what it is.
00:40:48And the seventh way will also work. Okay, you see they are all equal. This is string concatenation. If I
00:41:07type it correctly or not, let me check it. Okay, just type it like this. I don't suggest you to
00:41:23do string concatenation. This plus sign, you see string, string operator plus string left, string right actually. So this is
00:41:34an operator. This is a plus operator.
00:41:37This has special meaning. And so what else can we do? Can we show? Okay, let's make another format of
00:41:49date time. Where was it? Okay, it was here. You see, I can format the date time as I wish.
00:42:00So I will format it a better way. I will find a better time. Okay, there is the time. So
00:42:13let's make it.
00:42:15Like this. Okay. So you see day D means it is the day of the month. DD is the date
00:42:32of the month from 01 to 31. This is 01 to 31. So let's use DD. I will type here
00:42:45so you will know. I will use it and I will use the full name of the day of the
00:42:59week.
00:43:03Let's use that as well. Let's put another thing. Let's put hh. So let's use this as a string format
00:43:38for our method. So my date this time will be providing like this.
00:44:01DD and HH. And let's write it. Let's see how it is looking. Okay, so it is formatted as 21
00:44:20Wednesday 01. So what we were expecting? We were expecting the day of the month. It is 21, correct. We
00:44:30were expecting the full name of day of the week. So currently we are at the Wednesday.
00:44:37Yes, it is Wednesday. And we were expecting the hour clock of the day as 01 to 12 with 12
00:44:46hour clock. And yes, it is 1 AM. So it is correct. Let's make another format. I'm copy pasting this.
00:44:55And this time let's get 24. Not this one. Let's get AM format. With AM format.
00:45:18There is ampm. There is am. Okay, so if I provide pt, it should give me ampm. Let's try it.
00:46:22Yes. Okay. So let's change the format a little bit more. This time I will type. I am going to
00:46:33put it as a command so you can check it here.
00:46:46Next time let's select something. Let's say we need from minute. Okay. Then I will use minute and I will
00:47:07use full name of the month. And then I will use ampm designator. So you can combine it as you
00:47:33wish. Zero always means the zero, the first data provided.
00:47:40And in this case, we are providing in our method as a first data, this one. Okay, date time. So
00:47:48this time I'm going to provide mmm then mm and tt. So let's check it out. Okay, October, the full
00:48:06name of the month. Then 21 is the current minute as you can see, 21.
00:48:14And the AM means the after 12 o'clock midday. I mean the midnight. I can change the culture too.
00:48:28Currently it uses my system culture which is English US. However, we can change it as well. But let's make
00:48:41it later.
00:48:43So we have seen string format date time, format date time. And I can access date time individual values as
00:48:54well. How can I do that? I can do that like this. Date time now and minute. You see it
00:49:20will show me the current date time minute. And let's access the variable we used here.
00:49:33This one, let's say I will access the seconds. I will access its second parameter. I can access the year
00:50:04as well. And when I run it, current date minute is 24 seconds of my date. It was 0 second
00:50:24and the year is 2020. I can also do this. Let's say date time.
00:50:32My next year for let's say plus 35 hours. And I will make my date add. You see when I
00:50:47click add, it shows me all of the options that it has. I can add days, I can add hours,
00:50:54I can add milliseconds, I can add minutes. I will add hours and 25.
00:51:03You see it takes double value so I can add 1.3 hours as well. I will add like this.
00:51:13This also works. Okay. And I am just adding this. And I will print this to the screen as I
00:51:22want. How am I going to do that? Let's say I will be adding that.
00:51:34After, I don't know will this work. Let's check it out. First I will run this and see if it
00:51:57is working. Okay, that is work. Yeah, so we need to make it like this. Like this. So let's just
00:52:33type it with as year. Where is the year?
00:52:43Here. Okay, this is correct here. And then I will type the full month. The month was big mm, I
00:53:00guess. Let's check from here. Okay, big mm, not this one. Okay, this one. And I will type the day
00:53:15of the month. So day of the month will be dd if I remember. Yes.
00:53:27Type the day of the week as ddd. And I will type the hour as hh with 24 hour clock.
00:53:42And then I will type the minute as small mm, I guess. Yes. I will type am or pm. And
00:53:55let's check it out.
00:54:06354 hours. I need to write this to this. Okay, date is after 355.32 hours is 2020 October 21
00:54:30Wednesday. Okay, it shows the current date. Why?
00:54:40Because we made a mistake, which is we added this. However, we didn't provide this as a value here. So
00:54:49when I change it, you will see. Let's type it like this. Okay, now let's compare. Okay, so current date
00:55:15is 2020, October 21, Wednesday 1, 28 a.m.
00:55:29It will be 2020 November. You see we are moving to November. November 4th, Wednesday and 2048 PM. Okay. So
00:55:44you see this is how we add to the date. And this is string manipulation also. Okay. So I will
00:56:08show you another thing.
00:56:09You see this was a plus operator. Plus operator supports string plus numeric such as. By the way this var
00:56:21means it is dynamically assigned according to the right side of the equation. The type of the equation. I will
00:56:32make it like 12. This is the double plus. So this will be a string.
00:56:50Because when plus operator is assigned, it shows string operator plus sign object left and string right. So it will
00:57:00convert that left object into a string. Okay. And then I will make another thing. This will be, you see,
00:57:31double. Because when you double plus integer, it will convert it to a double.
00:57:44And let's make number 3. So you see this is taking according to how you construct the command. This time
00:57:57it is double operator plus sign, double left and double right. So this integer is inherently converted to the double.
00:58:12This is an inherent conversion. Okay, number three will be this time I will float plus let's say double. Okay,
00:58:32so this will become a double. You see float plus double means it will convert to a double. So it
00:58:41is up to you. Or let's make it date time.
00:58:48Does it work? No, because the plus operator doesn't have date, time and int. You see when you read it
00:58:56here. It shows the operator plus cannot be applied to operands of type, date, time and int. So I have
00:59:09to find something else. I don't know. Maybe I can say near time span.
00:59:21And from this time span, it gets 5. Let's make it hours in some minutes. I will add 24, 5
00:59:29hours, 32 minutes and 11 seconds. Now it works. So time span defines a time span. So in this case,
00:59:44this time span will define 355.
00:59:49Hours. 32 minutes. And 11 seconds. Okay. So. Time spawn. Check out this one. In this case it will be
01:00:06a date time. You see. When I run it. Okay. You see it is. Written as like this. You see
01:00:21the float plus. Integers. Double plus integer is written like this. So.
01:00:30Double is held at C sharp not exactly as you type. So you were expecting 64.54. However, it didn't
01:00:53came that way because this is how double is.
01:01:02Alt in the C sharp. And how can I change, fix it? Let's put it work this way. Let's check
01:01:11it out. Okay, still not that way. So this is not the solution. The solution will be another thing in
01:01:36that case. Let's say double. And I will make it. So round takes.
01:03:38Internally floats and doubles are represented in binary according to the IEEE 754 standard. Your number.
01:03:4650.8467178 can't be exactly represented in binary, much like one-third can't be exactly represented in decimal, without repeating
01:03:56digits. According to the standard, the number as a float is stored as hexadecimal 424B6304. This is precise to 24
01:04:06bits, or 6 to 9 decimal digits. Now, reinterpreting that number according to the standard we get.
01:04:15Okay, so this number is actually stored as this number. That makes the difference. So if I want to print
01:04:24it as I wanted, I'm going to use another string format. It will be string. So this will not work.
01:04:37It will work as like this. When I round it, it will round it.
01:04:54Ah, okay, I didn't call it. So when I call it, you need to assign it. Okay, yes, now it
01:05:06is rounded to exactly as I wanted. Okay, so mat round works as intended. I can also fix it like
01:05:26this. Instead of rounding, I can write it like this. So this time I am telling to setting and you
01:05:46see it can take when you.
01:05:49Write string double operator. It can take iFormatProvider. You see another format and string format. So I will provide a
01:06:00string. And n means it is numeric and number I will give will show how many numbers after the floating
01:06:11point. So I am going to set it as a tree and you will see how it is printed on
01:06:17the tree.
01:06:20So it is printed on the screen as 544. And you see 544. So it will only print three numbers
01:06:29after the floating point. So you can also use this. Or you can type it as like this. Zero. And
01:06:41it will just type as this. So it has rounded it to the let's say closest variable.
01:06:55However, if I want it to be fluid, let's make it fluid. What does fluid do? Fluor means returns the
01:07:13largest integral value less than or equal to the specific double precision floating point number. So it will be at
01:07:21least less than or equal. So let's try it again. When you fluid it is 64 you see. So you
01:07:43need to be careful how you are manipulating.
01:08:15Okay, let's continue. I will show you some examples of integer as well. So what will this print do you
01:08:46think? It will print three because integers are always full root. I can also make another example.
01:09:078 over 3. This will print 8 or 9. Which one do you think? Print 8. Because integers are always
01:09:27fluid. Oh, sorry, I have written incorrectly. Okay, you see it is fluid to 8. All right. So let's also
01:09:57change the system culture. So let's see.
01:11:07So it says this does not exist in the current context. When I click to show hints. Okay, it is
01:11:15not working. So it looks like I need to. This thread is not existing in there. So I am clicking
01:11:42this using some threading. Okay, it is not working. And I am going to use this. I am going to
01:12:03set a new culture info.
01:12:06So how am I going to do that? I'm going to do that as culture. Culture takes in culture or
01:12:25think name. I'm going to write this. You will see how the culture makes difference. Current culture is enus. So
01:12:51when it is enus, it is printed as this.
01:12:56It is printed as this. You see how the format automatically changes according to your computer's culture or the threads
01:13:06set culture. We will see more about threads in the future. The thread is the let's say application domain where
01:13:21that method is currently running.
01:13:27We will see more about that in future as I said. I will show another example of how culture makes
01:13:34difference. So let's say. Okay. And when I write this. After I set that to the Turkish culture. Okay. In
01:14:32US it is printed as this and in Turkish it is printed as this.
01:14:36So this makes an important difference. Because in Turkish, the floating point separator is comma. However, in English, the floating
01:14:48point separator is point. It's dot. Let's make this a bigger number. So I will make this as a and
01:15:02I will print this as and two.
01:15:08Let's make it like this so you understand better. Okay. Let's see the difference. Okay. So in US, the thousand
01:15:34separator is comma and the floating point separator is dot. And in Turkish, the thousand separator is dot and the
01:15:43floating point separator is comma. So when you convert numbers into the double.
01:15:51In Turkish or in English, it makes difference. Let's show that as an example as well. I will use convertTo
01:16:02method. I will write it like this. ConvertTo. Convert is let's say a class of system. Convert a base data
01:16:53type to another base data type. So convert method.
01:16:58Let us convert base data types between them. I will convert to this one. Let's say I will convert also
01:17:27this one. Let's say this is the first one. You should be careful when coding according to your let's say
01:17:51System culture language. So first wall converted. Second wall converted. Let's type it. I will make it as a convert.
01:18:19Zero. One. And I will provide the arguments. First argument will be this one. Second argument will be this one.
01:18:54Third argument will be.
01:18:56This one. Not argumentally. I can also type this as this. And then I will click ctrl double p. Ctrl
01:19:35p double. I mean control. Okay. Let's run this and see how they are converted. Okay. So it says input
01:19:56string was not in a correct format. Why? Because that is.
01:20:04Floating point separator in United States. And therefore, it gives an error. So I will use instead of convert method,
01:20:17I will use try to convert which is same. However, it prevents or let's make it try catch or try
01:20:27to convert. Okay, this fails. So I will write it like that.
01:20:43I will use try parse. Try parse will take a string. And if it parses, it will parse the value.
01:20:57So as it takes first parameter as string. And second parameter will be this. And I have to provide out.
01:21:24But it can't understand. Or I could make it like this as well. So now it will understand it was
01:21:35a double.
01:21:43Okay, first parameter, this one, converted to double as this one. So it works. And this one converted to double
01:21:52as zero because it is not matching. You see the difference? Okay, in Turkish, the opposite will happen. Let's try
01:22:07in Turkish. Okay, I don't need this. I will just make it like this. And then I run it.
01:22:25Okay, it is giving an error this time for this one. So I'm going to make this as typearse method
01:22:36as well. So typearse tries to parse it as double and it fails. It is keeping its old value. So
01:22:44let's make it x0, 1, negative 0, 1. So you will see what I mean. Okay, and let's try.
01:23:09Okay, so this one converted as zero and this one converted as double. So when the conversion fails in tripars,
01:23:21the value assigned is zero. It says, Converse the string representation of number to its double precision floating point number
01:23:32equivalent. A return value indicates whether the conversion succeeded or failed.
01:23:38Returns true if s was converted successfully, otherwise false. It returns boolean double and assigns zero to this variable if
01:23:51the conversion fails. So we can make it like this. We can say if true to fault if usage.
01:25:15In try parse method, I will assign this as a false negative. If this one failed, okay. These are boolean
01:25:29values and this method returns a bool value. You see it is displayed here as it returns bool value. And
01:25:40I will make it like this. Let's make it like this. And when I run it, you will see.
01:25:47The failed one will be the number I have assigned. Okay, so this one converted to double as negative zero.
01:25:57This is the number I did set. And this one converted as double correctly. So you see the format system
01:26:06culture makes difference in formatting in conversation of numbers. You need to be careful.
01:26:15Please watch this video at least two times and code every line yourself. I'm going to upload this code to
01:26:24our repository. So you can also download it and check it. We will continue making more examples in future lessons.
01:26:33So don't be upset or don't be confused.
01:26:42Gradually understand more and more as we progress in lectures. Just watch the videos. Try to do in your home.
01:26:52Type yourself. Type every coding line yourself. Not just copy paste. And you will get better and you will understand
01:27:01better. Okay. I'm going to upload this to our repository now. So you can download our GitHub page.
01:27:47Alright, let's open our github page. I'm typing our channel name. I'm clicking our channel. And then I'm clicking to
01:28:11let's say playlist. And there is our playlist. And in the description. In the description it has a link to
01:28:26our github repository. And when I click it.
01:28:31And when I click lectures folder, you see the lecture tree has arrived. When I click it, I can see
01:28:36the inside files folders. And you can download it, copy it or clone it. Okay, hopefully see you next week.
01:28:49This is the end of the lecture. See you.