Questions tagged [automatic-properties]
219 questions
3
votes
3 answers
How to set an autoproperty in the constructor of a struct?
Why is this valid
public struct MyStruct
{
public MyStruct(double value)
{
myField = value;
}
private double myField;
public double MyProperty
{
get
{
return myField;
}
…

Simon
- 33,714
- 21
- 133
- 202
3
votes
5 answers
A C# to VB.Net conversion utility that handles Automatic properties correctly?
I hope this isn't considered a duplicate since it's more pointed than similar questions (I'm curious about a specific weakness in C# to VB.net conversion utilities).
I've been looking at using a tool like this .net code converter to convert a class…

Peter T. LaComb Jr.
- 2,935
- 2
- 29
- 44
3
votes
3 answers
C# automatic property
Does the automatic property of C# 3.0 completely replace the filed?
I mean,I can directly use the property instead of filed as property serves as private backing field.(sorry,I understand like that only).
int a;
public int A
{
get;set;
}

user196546
- 2,513
- 4
- 23
- 18
3
votes
2 answers
C#3.0 Automatic properties with extra logic
How can I rewrite he following code using C#3.0 automatic properties?
private int _myValue;
public int MyProperty
{
get { return _myValue;}
set
{
if (value > 0)
{
…

user366312
- 16,949
- 65
- 235
- 452
2
votes
4 answers
How to customize Auto Properties in C# 3.0
Before C# 3.0 we done like this:
class SampleClass
{
private int field;
public int Property { get { return this.field } set { this.field = value } }
}
Now we do this:
class SampleClass
{
public int Property { get; set; }
}
(Look ma! no…

Jader Dias
- 88,211
- 155
- 421
- 625
2
votes
2 answers
Apply subversion auto props on a certain file on every commit
Is it possible to apply subversion auto props on every commit on a certain file (even if it is not modified)?
The reason I'm asking is that I'm working on an application which contains a version string in one source file (a constant actually) which…

scravy
- 11,904
- 14
- 72
- 127
2
votes
4 answers
Aren't automatic properties in C# causing ovehead?
When I have automatic propertie and I try to access it from within it's class, it seems like an overhead, because I use a function to access a member of my class instead of just accessing it directlly.
If this is correct, maybe I should consider not…

geniaz1
- 1,143
- 1
- 11
- 16
2
votes
1 answer
Config.GetSection with invalid class property names
Using IConfigurationRoot extension method
public static T GetSectionAsObject(this IConfigurationRoot configuration, string key)
{
return configuration.GetSection(key).Get();
}
I am retrieving sections from configuration file as…

chuftica
- 160
- 8
2
votes
1 answer
Is there a Reflector add-in or other tool that will handle auto properties?
Reflector shows this for auto properties:
public string AddressLine1
{
[CompilerGenerated]
get
{
return this.k__BackingField;
}
[CompilerGenerated]
set
{
this.k__BackingField =…

Jonathan Parker
- 6,705
- 3
- 43
- 54
2
votes
1 answer
VB.NET Auto-Implemented Properties - Compatibility between VS2010 and VS2008
I am working on an ASP.NET project where I use VB.NET within Visual Studio 2010. Some of the other developers on the project are using Visual Studio 2008. We all check our code into single SVN repository. I would like to start using Auto-Implemented…

webworm
- 10,587
- 33
- 120
- 217
2
votes
3 answers
Auto-implemented get/set properties
Is there any downside to letting C# create the private backing fields that are generated by using the automatic property creation (ie {get; set})?
I am aware that it is automatic and therefore you cannot customize the get/set, and would like to know…

markm247
- 97
- 9
2
votes
3 answers
Is there a way to get Visual Studio 2008 to stop formatting my AutoProperties?
In Visual Studio 2008's Options > Text Editor > C# > Formatting, I have the following settings ticked.
Automatically format completed statement on ;
Automatically format completed block on }
This is really helpful for when I'm writing a method or…

mezoid
- 28,090
- 37
- 107
- 148
2
votes
2 answers
Is there a snippet for an auto-property in VB.NET?
In Visual Studio 2010, for VB.NET, the "Property" + Tab + Tab inserts a full property implementation. Is there another snippet for inserting an autoproperty?

Chris
- 2,959
- 1
- 30
- 46
2
votes
4 answers
Why do we need to create class variables to get and set a property?
Very simple question but I find it very important to understand why we do it.
I can create a property in the class as follows:
1st Approach:
public class MyClass
{
public string MyProperty {get;set;}
}
2nd Approach:
public class MyClass
{
…

InfoLearner
- 14,952
- 20
- 76
- 124
2
votes
3 answers
When Do C# Auto-Properties Initialize?
On a webforms .aspx page system, the master page has a few properties auto initialized, as such
public bool MyProp => bool.Parse(Service.Settings["YorN"]);
Profiling page load, I see that between the PreRender event, and the initialization of one…

JNF
- 3,696
- 3
- 31
- 64