Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

C# Programming

Named parameters


Is it possible to make use of named parameters outside of Attribute?

If so how :)

Thanks in advance.

Paul <paul.tho@corpoflondon.gov.uk> wrote:
> Is it possible to make use of named parameters outside of Attribute?

> If so how :)

What exactly are you after? C# only supports positional parameters for
methods, if that's what you mean.

--
Jon Skeet - <s@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

-----------------------------------------------Reply-----------------------------------------------

"Paul" <paul.tho@corpoflondon.gov.uk> wrote:
> Is it possible to make use of named parameters outside of Attribute?

> If so how :)

C# 3.0, which ships this year, brings what you're looking for - they're
called Object Initializers. You can read all about them at:
http://blogs.msdn.com/wriju/archive/2007/04/12/c-3-0-enhancements-obj...

This is something that I've missed for a while too, as I quite like doing it
with Attributes.

--
Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP
http://www.coversant.com/blogs/cmullins

-----------------------------------------------Reply-----------------------------------------------

Thanks,

I have seen a demo of that at the last DevWeek. It does look good.

Paul

-----------------------------------------------Reply-----------------------------------------------

    This isn't named parameters though.  It allows you to set accessible
properties/fields after using new to construct the object.  Very different
things.

--
          - Nicholas Paldino [.NET/C# MVP]
          - m@spam.guard.caspershouse.com

"Chris Mullins [MVP]" <cmull@yahoo.com> wrote in message
news:%23kgzP25pHHA.1148@TK2MSFTNGP06.phx.gbl...

I do like the feature, but don't see at the moment that it actually saves
much typing other then a newline or so and in some ways can be a bit harder
to look at.  Being able to stick more on one line does not equal clearer
code imo:

c = new C()
c.Name1 = "name";

-vs-
c= new C(){Name1="name"}

What are all the advantages?

--
William Stacey [C# MVP]

"Chris Mullins [MVP]" <cmull@yahoo.com> wrote in message
news:%23kgzP25pHHA.1148@TK2MSFTNGP06.phx.gbl...

| "Paul" <paul.tho@corpoflondon.gov.uk> wrote:

| > Is it possible to make use of named parameters outside of Attribute?
| >
| > If so how :)
|
| C# 3.0, which ships this year, brings what you're looking for - they're
| called Object Initializers. You can read all about them at:
|
http://blogs.msdn.com/wriju/archive/2007/04/12/c-3-0-enhancements-obj...
|
| This is something that I've missed for a while too, as I quite like doing
it
| with Attributes.
|
| --
| Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP
| http://www.coversant.com/blogs/cmullins
|
|
|

-----------------------------------------------Reply-----------------------------------------------
It saves some typing  when adding it to a List :).

List<C> lst = new List<C>();
lst.Add(new C(){Name1="name0"} );
lst.Add(new C(){Name1="name1"} );
lst.Add(new C(){Name1="name2"} );
lst.Add(new C(){Name1="name3"} );

-----------------------------------------------Reply-----------------------------------------------

Maybe... personally I've never had any problem with the 2 existing
patterns (below). It is a little more succinct, but not a lot...

lst.Add(new C("name0")); // if a suitable ctor exists
// or
lst.Add(CreateC("name0")); // if some (locally-specific-set-of)
properties must be used
// ... (the following implementation-(rather than type-) specific
method is scoped to the class using it)
private static C CreateC(string name) {
  C c = new C();
  c.Name = name;
  return c;

}
"Michael Huber" <huberm@gmail.com> wrote in message

news:1181118062.937094.55230@q66g2000hsg.googlegroups.com...

oh thanks

its very nice :)

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc