automatic-properties

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 library to VB since I'm the only one in my group comfortable with C#. The problem I've ru...

Why is it necessary to call :this() on a struct to use automatic properties in c#?

If I define a struct in C# using automatic properties like this: public struct Address { public Address(string line1, string line2, string city, string state, string zip) { Line1 = line1; Line2 = line2; City = city; State = state; Zip = zip; } public string Line1 { get; protected ...

C# Automatic Properties - Why Do I Have To Write "get; set;"?

If both get and set are compulsory in C# automatic properties, why do I have to bother specifying "get; set;" at all? ...

.NET - Error trying to compile Automatic Properties

I'm trying to compile a POCO with this code public class MenuItem { public string Name { get; set; } public string Url { get; set; } } I keep getting compile errors on the gets and sets with messages like: 'MenuItem.Name.get' must declare a body because it is not marked abstract or extern. What am I missing? I'm com...

What's the best way to call INotifyPropertyChanged's PropertyChanged event ?

When you implement the INotifyPropertyChanged interface, you're responsible for calling the PropertyChanged event each and everytime a property is updated in the class. This typically leads to the following code : public class MyClass: INotifyPropertyChanged private bool myfield; public bool MyField { ...

How do I write private set auto-properties in VB 10?

in C#: public string Property { get; private set; } in VB? Please vote or/and share your ideas! ...

Is this the correct syntax for auto properties?

I've been programming for so long its hard to keep up with language changes sometimes... Is it really ok to set properties like this after .net v2 public string LocaleName { get; set; } Not requiring an inner field? Seems like the compiler takes care of this lately? ...

How to return a new instance of an object in C# Automatic Properties

Is it possible, using C# Automatic Properties, to create a new instance of an object? in C# I love how I can do this: public string ShortProp {get; set;} is it possible to do this for objects like List that first need to be instantiated? ie: List<string> LongProp = new List<string>(); public List<string> LongProp { get { ...

C# 3.0 :Automatic Properties - what would be the name of private variable created by compiler

I was checking the new features of .NET 3.5 and found that in C# 3.0, we can use public class Person { public string FirstName { get; set; } public string LastName { get; set; } } instead of private string name; public string Name { get { return name; } set { name = value; } } If i use the Automatic Properties,what ...

C# Automatic Properties - Still null after +=?

This seems like a bug to me... I accept that automatic properties, defined as such: public decimal? Total { get; set; } Will be null when they are first accessed. They haven't been initialized, so of course they are null. But, even after setting their value through +=, this decimal? still remains null. So after: Total += 8; Tot...

Is there a way to make readonly (not just private) automatic properties?

Automatic properties let me replace this code: private MyType myProperty; public MyType MyProperty { get { return myPropertyField; } } with this code: public MyType MyProperty { get; private set; } with a few changes here and there - but is there a way to replace this code: private readonly MyType myProperty; public MyType MyP...

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) { _myValue = value; } } } If it is...

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; } ...

Automatic Properties Problem

Hi , At the moment i'm useing .Net 3.0 but I don't get it how to use Automatic Properties . For example if i want write this sample code via Authomatic Properties , What should i do ? private string _name = string.Empty; private string _family = string.Empty; //A field with default value private DateTime _releaseDate = System.Date...

Automatic transformation from getter/setter to properties

I have a big libray written in C++ and someone created an interface to use it in python (2.6) in an automatic way. Now I have a lot of classes with getter and setter methods. Really: I hate them. I want to reimplement the classes with a more pythonic interface using properties. The problem is that every class has hundreds of getters and...

Why do C# automatic properties not support default values like VB 2010?

Looking at the new VB 2010 features, I stumbled upon support for Auto-Implemented Properties. Since I'm working with C#, this seemed quite familiar, but I noticed that VB did add a feature I would love to have in C#: setting a arbitrary default value for the auto-implemented property: I really like the clean usage of auto-properties...

MonoTouch - Fields vs Automatic Properties

Is there a noticeable performance difference when using fields instead of auto properties? What about if I'm deserializing an array of say, 1000 JSON objects with 5 properties each? My iPhone domain model is basically a copy of the DTOs my web app uses for serialization to javascript. They all use auto properties by habit. I'm conc...

How to properly define class properties?

When defining a new class within a project what is the correct/best practice for doing so? In the past I have created classes such as: public class MyClass { public string FirstName {get; set;} public string LastName {get; set;} } Normally I’d use a class such as this for the creation of collections within a proje...

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; } Lovely! But what am I supposed to do if I want to, say, convert the Name string using the...

Why doesn't Java have automatic properties like C#?

C# has automatic properties which greatly simplify your code: public string Name { get; set; } public string MiddleName { get; set; } public string LastName { get; set; } Whereas Java has you write this much code: private String name; private String middleName; private String LastName; public String Name(){ return this.name; } e...