No menu items!
7 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

The Best LV Limited Edition Neverfull Styles Youll Love!

Okay, so here’s the lowdown on how I scored my LV Limited Edition Neverfull. It’s a bit of a story, so buckle up! It...

Aaliyah iconic outfit: See The best looks and more info

So, I was messing around the other day, kinda thinking about old-school styles, you know? And Aaliyah popped into my head. Man, her vibe...

Where can you find the best Seiko mens perpetual calendar watch 5 hands watch? See top deals and models here.

Alright, let’s talk about this Seiko perpetual calendar watch I got. The one with five hands. It wasn’t my first Seiko, definitely won’t be...

Get the best deals on base de kylie jenner today.

So, I got thinking the other day about Kylie Jenner. You see her everywhere, right? Big houses, fancy cars, the whole deal. And I...

Which Lady Gaga Outfit is the Most Famous One? (Check Out All Her Unforgettable Looks Now!)

So, I got this idea stuck in my head the other day. You know how Lady Gaga just pulls off these wild looks? I...

LEAVE A REPLY

Please enter your comment!
Please enter your name here