Is there a way to define a property with default get/set functionality for a variable?

public String Name {get; set;}

This defines a public property called Name. The compiler will generate the backing field and all the code needed for you. You can also include access modifiers:

public String Name {get; private set;}

In this case the set is private, so can only be called from within the object.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.