From the course: C# Essential Training 1: Types and Control Flow

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Understanding nullable reference types

Understanding nullable reference types - C# Tutorial

From the course: C# Essential Training 1: Types and Control Flow

Understanding nullable reference types

- [Narrator] We've done a few things here with some nullable types. Let's look at a common problem that we run into in programming. And that is the no reference exception. Got a method here I just pasted in called pad and trim. I've used it a lot lately to pad and trim strings for file output. So I've got a string input, a final length that I want the string to be and a pad character. So I might be adding zeros to the end of something or the beginning. I might be adding spaces. I need the string to be a certain length, and I'm going to fill out the empty space with a particular character. So I return, I just take that string input. I trim it, so I get rid of all the space. And then in this case, I'm going to pad the left. I'm going to say how long I want it to be and what that pad character is. So we can come up here. I can tell I want to write out pad and trim and take my input variable from above. Maybe I want it to be 15 characters and I want to make it filled with zeros. But if we…

Contents