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

male bedroom ideas on a budget how to decorate affordably today

Alright, so I’ve been stuck with this boring bedroom setup for months – just my old mattress on the floor, those cardboard boxes pretending...

Photo finish track buying guide? Key features to check before purchase.

So last month I got obsessed with timing track events precisely, thought a photo finish system would solve everything. Big mistake. Started digging online...

Where to buy affordable builder gel as nail glue? (Top cheap options reviewed for you)

My Hunt for Cheap Builder Gel as Nail Glue So my regular nail glue ran out last Tuesday, and I remembered some beauty bloggers talking...

How to Choose Nude Nail Colors That Flatter Your Skin Tone Best Tips Inside

Okay, so I’ve been seeing a ton of “perfect nude nail” pics online lately, right? But every time I tried one myself, it just...

Where to Buy Gucci Christmas Tree Official Stores and More

So lemme tell you how I hunted down that Gucci Christmas tree this year. Saw it online, thought it looked wild fancy, and just...

LEAVE A REPLY

Please enter your comment!
Please enter your name here