Questions tagged [automatic-properties]

219 questions
3
votes
4 answers

Why are my auto-implemented properties working in ASP.NET 2.0?

I'm using the auto-implemented properties syntax in the C# source files of my ASP.NET Web Application: public int IdUser { get; set; } ... this.IdUser = 1; The Target framework of the project is .NET Framework 2.0. It compile and seems to run…
Clément
  • 729
  • 6
  • 18
3
votes
2 answers

Must declare a body because it is not marked abstract or extern (CS0501)

Im newbie in C# and don't know its syntax. But I know a bit about other languages (Java, C++). I downloaded GLWidget project and tryed to build it. However I got an error CS0501 at these lines (with { get; set; }): namespace Gtk { …
itun
  • 3,439
  • 12
  • 51
  • 75
3
votes
2 answers

quick and easy setters and getters?

It's allowed to do: public int Age { get; set; } but does the application create/allocate the space for the variable? I usually do private int age = 0; public int Age { get { return this.age; } set { this.age = value; } }
Jason94
  • 13,320
  • 37
  • 106
  • 184
3
votes
2 answers

Inherit from abstract class with properties of another type (.NET 3.5, C#)

I have 3 following classes: public class BaseProperty1{ public string Property1 {get; set;} } public class ChildProperty1 : BaseProperty1 { } public abstract class Base{ public abstract BaseProperty1 bp1 {get; set;} } I'm trying to…
Masha
  • 327
  • 1
  • 6
  • 17
3
votes
4 answers

Do we need to lock when we get the property in C#

In C#, is it necessary to lock when getting a non volatile property? I know we need to lock when setting the property. how about getting? Now 3.0 provide automatic property, is it thread safe itself?
user705414
  • 20,472
  • 39
  • 112
  • 155
3
votes
7 answers

Setting property or field when inside of class?

Well I am learning properties and I am not sure about the following: class X { private int y; public X(int number) { this.Y=number; // assign to property OR this.y=number //? } public int Y; { get; set; } }
Mocco
  • 1,183
  • 2
  • 12
  • 25
3
votes
5 answers

C# - Difference between Automatic Property and returning a backing field?

Simple question I imagine, but what is the difference between these lines of code: Code 1 public int Temp { get; set; } and Code 2 private int temp; public int Temp { get { return temp; } } My understand was that an automatic property as per…
JuniorDeveloper1208
  • 448
  • 1
  • 5
  • 15
3
votes
1 answer

How do I set a custom Author name in TortoiseSVN locally?

I am using auto props to populate the $Id$ tag with TortoiseSVN but it is using the author name that is the name of the computer, in this case 'Peter'. I want it to use my name instead of the computer's account name. I am using Vista on this…
james
  • 3,543
  • 8
  • 31
  • 39
3
votes
1 answer

When i make an automatic Property what happen's in the background?

edit : a completely different question than this i'm asking how auto-properties work internally When i make an automatic Property what happen's in the background ? This Equals to public int SomeProperty {get; set;} This private int _someField; …
RazaUsman_k
  • 694
  • 6
  • 20
3
votes
1 answer

What is the use case for Access.BackingField in Fluent NHibernate?

The documentation for Access.BackingField() indicates that this: Sets the access-strategy to use the backing-field of an auto-property. I understand that auto-properties get compiled with backing fields, but if the property is by definition a…
Jay
  • 56,361
  • 10
  • 99
  • 123
3
votes
1 answer

Auto-properties: Checking/validating during the "set"

I think we can all agree that Automatic Properties in C# 3.0 are great. Something like this: private string name; public string Name { get { return name; } set { name = value; } } Gets reduced to this: public string Name { get; set;…
Pretzel
  • 8,141
  • 16
  • 59
  • 84
3
votes
0 answers

Disable code coverage of auto-properties by NCrunch

Recently I've moved to Visual Studio 2015. I use NCrunch for checking code coverage, which I also upgraded. The main difference that I noticed was that NCrunch now also includes coverage auto-properties, which wasn't the case with Visual Studio…
3
votes
1 answer

Svn import with auto-props & pre-commit hook

My company's svn repo has a lot of MS Word docs in it. We've implemented a policy that all .doc files must have the svn:needs-lock property set to prevent parallel access on files that are hard to merge (we've also done this for xls, ppt, pdf…
James Tisato
  • 141
  • 5
3
votes
2 answers

How to reset svn-properties according to new SVN config?

Recently I made a bunch of changes to my local svn config file. Mainly I corrected svn:mime-type properties of about 15 different file types. Now I need reset all previously checked in files according to this new configuration. SVN seems to trigger…
Dilshod Tadjibaev
  • 1,035
  • 9
  • 18
3
votes
1 answer

Error on Constructing Struct in C#

Sorry for the genericness of the title, I really don't understand the error that I'm receiving. So I'm following this tutorial on C#, and I'm up to the section "Structs & Memory Management". Around the 5:30 mark, he begins creating a Color Struct,…
marked-down
  • 9,958
  • 22
  • 87
  • 150