Depends what you are doing. If you are working on code that can take any type of object (such as Console.WriteLine for example) you have no choice except to use
object
declarations:
public void MyWriteLine(string format, params object[] data)
{
...
string s = data[i].ToString();
...
}
Because everything is ultimately derived from
object
a variable of that type will accept any class as a value - and the inheritance system will then sort out the necessary method to execute based on the actual value type at runtime.
It's a problem when you use it inappropriately: for example using an
ArrayList
instead of a
List<T>
because you can "include any object in it" - but it makes life harder down the line because you have to do runtime verification and conversion before you can use the actual values type.
When you can use named types, do. Only use
object
when you really need to.
[edit]
Thinking about it, if you are talking about actual Anonymous types rather than the object class, then that's a different matter - most of the time when you use anonymous types it's because there is no choice: Linq for example wouldn't work very well without them.
Again, it's down to appropriate use: if you are passing a value out of a method, it should be a named type (or the outside world can't easily use use it). But if you are going to use the type temporarily:
var results = listOfMyClass.Where(m => m.FirstName.StartsWith("M")).Select(m => new {Name = m.FirstName + " " + m.LastName, Email = m.Email});
foreach (var x in results)
{
}
And then discard it, it's pointless to build a new "real" class.
[/edit]