No menu items!
12.5 C
Washington
No menu items!

Using Automatic Field Features: A Beginners Easy Guide.

Date:

Share:

Today I messed around with something called “automatic field” in C#, and I wanna share what I did and how it went. It’s pretty basic stuff, but hey, we all start somewhere, right?

Using Automatic Field Features: A Beginners Easy Guide.

Getting Started

So, I was looking at this code example online and decided to try it out myself. I fired up Visual Studio and created a new console application. You know, the usual – File > New > Project, choose Console App, give it a name, and hit Create.

The Experiment

First, I made a simple class, I’m calling it “MyClass” for now. Just a basic class, nothing fancy:


public class MyClass

Then I added a private string member, and I want that C# can automatic create get and set properties, just like this:


public class MyClass

Using Automatic Field Features: A Beginners Easy Guide.

private string myValue;

Then I want use myValue, I need add get and set method, like this:


public class MyClass

private string myValue;

public string MyValue

Using Automatic Field Features: A Beginners Easy Guide.

get { return myValue; }

set { myValue = value; }

I have set myValue as private,so I can not use myValue directly.

The Result

It worked! I mean, of course, it did, it’s pretty simple. I can set the value and get it back no problem. I added a little bit of code in the Main method to test it out:


static void Main(string[] args)

Using Automatic Field Features: A Beginners Easy Guide.

MyClass instance = new MyClass();

* = "Hello, Automatic Field!";

This is how you use an automatic field, I think this is the best C# * makes the code super clean and easy to read. And it’s less typing, which is always a win in my book.

Subscribe to our magazine

━ more like this

Where is Tina Versace now? (Discover what she is doing away from fame)

My Dive into the Story of Tina Versace Okay, so I was just kinda browsing stuff about fashion history the other day, you know, going...

Why is the truman show staircase moment so famous? Exploring the impact of this powerful film ending.

Alright, let me tell you about this project I was messing with a while back. Gave me some real ‘Truman Show staircase’ vibes, you...

Who is Brian Nygard? All about Brian Nygard career and life

Alright, let’s talk about my deep dive into brian nygard’s stuff. I stumbled upon his work a while back, and I gotta say, I...

The Tannery Boylston: Discover Authentic Leather Craftsmanship

Okay, so today I’m gonna walk you through my little adventure with the ‘the tannery boylston’ project. It wasn’t exactly smooth sailing, but hey,...

Is Sol de Janeiro Sunscreen the right choice for your skin?

Okay, so let’s talk about this sunscreen I’ve been trying out – the Sol de Janeiro one. I’ve seen it all over the place...

LEAVE A REPLY

Please enter your comment!
Please enter your name here