とりこらぼ。

Learn from yesterday,
live for today,
hope for tomorrow.

目次

Blog 利用状況

ニュース

プロフィール

  • 名前:とりこびと
    とるに足らない人間です。

  • Wankuma MVP
    for '平々凡々'

Web Site

  • Memo(Of T)

もうひとつの Blog

広告っぽい

書庫

日記カテゴリ

Visual Basic 2008 の新機能 - オブジェクト初期化子(名前付きの型について) -

# 型推論についてはそんなに確固たる信念が自分になかったというか、そんな感じですwというわけで、次の新機能にそそくさとw

Visual Basic 2008では オブジェクト初期化子 という機能が新しく追加されました。

MSDN:オブジェクト初期化子 : 名前付きの型と匿名型※ 匿名型については別のエントリで書きます。

オブジェクト初期化子は、あるオブジェクトのインスタンスの初期化の際に、そのオブジェクトが持つプロパティを指定できるようになる機能です。

匿名型については後で書くので、今回は名前付きの型についてのサンプルです。まずは一番シンプルなもの。

Imports System.Windows.Forms
Public Class Program
    Public Sub Main()
        Dim f As New Form With {.Text = "ふぉ~む。", .Visible = True}
    End Sub
End Class

New キーワードで初期化した後にWith キーワードと {}で各プロパティを初期化します。各プロパティには「.」+ プロパティ名でアクセスできます。なお、実際には初期化子リストで指定されている順に指定したプロパティが初期化されます。上のコードは With ... End With ステートメントを使用した以下のコードと同じです。

Imports System.Windows.Forms
Public Class Program
    Public Sub Main()
        Dim f As New Form
        With f             .Text = "ふぉ~む。"             .Visible = True         End With
    End Sub
End Class

次のサンプルでは、ある一つのプロパティを別のプロパティの値を使用して初期化します。(初期化の内容はつっこまないでw)

Imports System.Windows.Forms
Public Class Program
    Public Sub Main()
        Dim f As New Form With {.Text = "ふぉ~む。", .Visible = .IsHandleCreated}
    End Sub
End Class

さて、これってコンストラクタで引数とって初期化すればいいんじゃね?とか、一瞬だけ思ったわけですが、この初期化子が実行されている時点では New キーワードによるインスタンスの初期化はすでに行われているということがコンストラクタ内の初期化との大きな違いです。なお、既定のコンストラクタ以外の引数を持つコンストラクタの場合でも使用できます。

投稿日時 : 2007年12月28日 16:48

Feedback

# re: Visual Basic 2008 の新機能 - オブジェクト初期化子(名前付きの型について) - 2007/12/28 17:50 まさる

ん~、個人的には微妙...

結局

Dim f As New Form With { _
.Text = "ふぉ~む" _
,.Visible = IsHandleCreated _
}

みたいに、"_"使って開業して書くだろうし。
それなら2番目のサンプルコードと余り変わらない気がします。

# re: Visual Basic 2008 の新機能 - オブジェクト初期化子(名前付きの型について) - 2007/12/28 17:51 まさる

開業してどうする(--;

"改行"です。

# re: Visual Basic 2008 の新機能 - オブジェクト初期化子(名前付きの型について) - 2007/12/29 9:18 R・田中一郎

VBだと、こうやって書くんですね。
面白いです!

# re: Visual Basic 2008 の新機能 - オブジェクト初期化子(名前付きの型について) - 2007/12/29 14:00 とりこびと

コメントありがとうございます。

>>まさるさん

>個人的には微妙

そうですねぇ。
この名前付きの型に対する初期化子だけではあんまし使わないかもしれないです。
とはいいますけど、この機能だけではなくほかの新機能と織り交ぜるといい使い方が見えてくるかもしれませんね~♪

>開業してどうする(--;

コピーとお茶汲みさせてくださいねw


>>R・田中一郎さん

>VBだと、こうやって書くんですね。

ですです。
いろいろ言語で個性がでてきてますね~。

# re: Visual Basic 2008 の新機能 - オブジェクト初期化子(名前付きの型について) - 2007/12/29 20:28 かるあ

With だとそのクラス以外も書けるしなー
そのクラスの初期化に注目してということならありなんじゃないかな。
あとはラムダで値を返したいときとかはいいですね。

# Visual Basic 2008 の新機能 - 匿名型 その1 - 2008/01/07 19:27 とりこらぼ。

Visual Basic 2008 の新機能 - 匿名型 その1 -

# <url>http://www.freeinsurquotes.com/|auto insurance quotes</url> 0574 <url>http://www.cheapquotes4you.com/|cheap car insurance</url> cdtxdf 2012/08/22 15:13 Emmly

<url>http://www.freeinsurquotes.com/|auto insurance quotes</url> 0574 <url>http://www.cheapquotes4you.com/|cheap car insurance</url> cdtxdf

# <url>http://www.multipleinsurquotes.com/|insurance quotes</url> %-))) <url>http://www.insuranceratesinminutes.com/|cheap auto insurance</url> hwuxcg <url>http://www.instantinsurquotes.com/|auto insurance online</url> dy 2012/10/04 6:23 Keys

<url>http://www.multipleinsurquotes.com/|insurance quotes</url> %-))) <url>http://www.insuranceratesinminutes.com/|cheap auto insurance</url> hwuxcg <url>http://www.instantinsurquotes.com/|auto insurance online</url> dyfirz

# <url>http://www.autosinsurance4u.com/|car insurance online</url> 528836 <url>http://www.get-autoinsurance.com/|car insurance qoutes</url> 067472 <url>http://www.oldstylelist.com/|auto insurance</url> tpfqsh 2012/10/17 1:37 Shermaine

<url>http://www.autosinsurance4u.com/|car insurance online</url> 528836 <url>http://www.get-autoinsurance.com/|car insurance qoutes</url> 067472 <url>http://www.oldstylelist.com/|auto insurance</url> tpfqsh

# <url>http://www.topinsuranceonline.net/|auto insurance quotes</url> :-((( <url>http://www.insuranceslife.net/|life insurance policies</url> nyjqg <url>http://www.ohautoinsurancequotes.com/|auto insurance quotes oh</url> 2012/11/04 0:18 Teige

<url>http://www.topinsuranceonline.net/|auto insurance quotes</url> :-((( <url>http://www.insuranceslife.net/|life insurance policies</url> nyjqg <url>http://www.ohautoinsurancequotes.com/|auto insurance quotes oh</url> 8)

# <url>http://www.compareinsurquotes.com/ |car insurance</url> gtel <url>http://www.hypothyroidismmeds.com/|synthroid</url> tibl <url>http://www.antiviraldrugonline.net/|acyclovir</url> 688 <url>http://www.carcovera 2012/11/24 8:04 Xaria

<url>http://www.compareinsurquotes.com/ |car insurance</url> gtel <url>http://www.hypothyroidismmeds.com/|synthroid</url> tibl <url>http://www.antiviraldrugonline.net/|acyclovir</url> 688 <url>http://www.carcoveragebrokers.com/|cheap car insurance</url> 7596

# ifFZDcpvCmo 2014/08/28 10:53 http://crorkz.com/

Q7Q0jy This site is known as a stroll-by means of for all of the info you needed about this and didn't know who to ask. Glimpse here, and also you'll undoubtedly discover it.

# HGETBvLueqRpRSHva 2014/08/29 12:39 http://nubiadesign.com/blog/

Would you be enthusiastic about exchanging hyperlinks?

# NZLhFOTEoNO 2014/09/02 17:51 http://protectmyholiday.com/oakley2.htm

It's laborious to search out knowledgeable people on this subject, but you sound like you recognize what you're speaking about! Thanks

# HOkxkZpUzFmGG 2014/09/06 20:14 http://www.campusspage.com

This web site can be a walk-through for all of the info you needed about this and didn't know who to ask. Glimpse right here, and you'll definitely uncover it.

# nNajSmnnYfJ 2014/09/06 21:34 http://metrocontests.com

It's exhausting to seek out educated folks on this matter, however you sound like you already know what you're talking about! Thanks

# poJETZiDiPttLDY 2014/09/10 16:22 https://www.facebook.com/SunsetValleyHolidayHouses

I'll immediately clutch your rss feed as I can not to find your e-mail subscription link or newsletter service. Do you've any? Kindly permit me understand so that I could subscribe. Thanks.

# kwgGXJuRHnkwrqOUa 2014/09/14 18:36 http://www.escortsinlondon.tv/

This web page can be a walk-through for the entire information you wanted about this and didn't know who to ask. Glimpse right here, and you'll positively discover it.

# WyLMaWecLURaVssqXX 2014/09/18 16:56 http://z9bi.info/story.php?id=92483

uVC1so I truly appreciate this blog article.Much thanks again. Awesome.

# cSuYmewePCplzSBO 2014/10/04 3:02 horny

7tpUvK http://www.QS3PE5ZGdxC9IoVKTAPT2DBYpPkMKqfz.com

# OXSFtGjjibsAC 2014/10/22 11:37 Amelia

What do you do? http://santafyme.com/buysildalis/ buy sildalis If one side is said to have dumped boxes, has the noisy neighbour also dumped exactly the same boxes all around his own garden? He even claims to own the garden of the house next door &ndash; indeed, he is keen to move into the next door house as well.

# YeKeMMyCgPsimBox 2014/10/22 11:38 Bailey

Could I ask who's calling? http://5passion.com/contact.htm diflucan 150mg Hollywood�s pre-eminent producer of tentpoles denied that the impending split was sparked by the huge disappointment of his last project with Disney - the box-office flop �The Lone Ranger.� Disney told analysts last month that the studio is anticipating a loss of between $160 and $190 million for the movie.

# CRMUGCvlerCa 2014/11/03 13:56 Dominic

A packet of envelopes http://skin-solutions.co.nz/what-is-ipl/ purchase bimatoprost pay pal online without rx Those increased outlays, in turn, could push up inflation-adjusted economic growth by 0.7% and increase employment by 900,000 jobs in the third quarter of 2014. Both numbers fall in the middle of CBO's estimated ranges for growth and jobs.

# UCxkzOdPkiJhRm 2014/11/03 13:56 Ella

I'd like to speak to someone about a mortgage http://skin-solutions.co.nz/what-is-ipl/ purchasing bimatoprost in the uk In tandem, the Government would convert its non-voting "B" share in RBS into a 100pc equity stake in the "bad bank", which would then be run down much in the same way as those of Northern Rock and Bradford & Bingley.

# KMscMuVSuEkfZ 2014/11/06 14:03 Donte

It's OK http://skin-solutions.co.nz/what-is-ipl/ purchase bimatoprost ophthalmic solution Skydrifter, you ask intelligent questions. I would assume that all of the concerns you cite were part of the certification process with the FAA. I think you could write to Boeing public affairs and they might be able to fill in some of the blanks.

# GwKobLNrlrWeuyvYkNY 2014/11/07 10:40 Johnie

I'm a trainee http://skin-solutions.co.nz/what-is-ipl/ holds erase purchase discount bimatoprost no rx four sharp In recent weeks the number of new infections in people hasdropped dramatically, thanks largely, experts say, to theclosure by Chinese authorities of many live poultry markets andthe summer season. But many virologists fear the human case ratemay pick up again with the return of autumn and winter in China.

# AMFhPkyjfamqP 2014/11/19 10:47 Marcos

US dollars http://macroprofitnewsletter.com/index.php/contact-us nizagara online As the crisis has evolved in Europe so also have thebailouts. At the beginning, taxpayers were the first to be hitto protect junior bondholders, senior bondholders and mostsacrosanct of all; depositors.

# DobcVLqtQqDIMVf 2014/11/19 10:47 Garfield

Another year http://www.ilbaccarodublin.com/reservation what is esomeprazole "I didn't come in here with a black shirt today because I didn't feel that I wanted to be stereotyped by the Waterfront Commission," he said, according to a transcript. "I think you guys do a good job in some things, but you're not helping us as you should be helping us.

# mKvZxtlozt 2014/11/19 10:47 Leslie

An envelope http://iopb.eu/humanbrand/ buy domperidone CQC said that the notices had been &ldquo;closed&rdquo; at 10 of the 11 trusts, who had acted to make improvements following the warnings, which were issued in the 12 months ending in March 2013.

# XXMhEEAleRpKfP 2014/11/19 22:02 Cedric

I'd like , please http://www.aos-inc.com/index.php/products naprosyn e 500 mg Pitching coach Chuck Hernandez talks to pitcher Nathan Eovaldi, second from left, after the Giants scored four runs in the first inning of the of the Miami Marlins vs San Francisco Giants game at Marlins Park in Little Havana in Miami on Friday, August 16, 2013. Pedro Portal / Staff Photo

# TZZhZTxVKF 2014/11/20 14:32 Patricia

Could I order a new chequebook, please? http://agrimeetings.com/contact-us buy tetracycline 500mg While things are in limbo, many investors are taking theirmoney out of U.S. municipal bond funds. They withdrew $2.24billion in the week ended on Wednesday, extending the funds'outflow streak to 10 weeks, according to Lipper, a ThomsonReuters company.

# NdFlZmjtBscUYVhgJT 2014/11/22 5:44 Wallace

I work here http://greenwoodsstatebank.com/personal-loans/ the best personal loans with bad credit The Obama administration last week unveiled a landmark proposal that would require new coal-fired power plants to capture at least some of the carbon pollution they emit, but the needed technology remains uncertain.

# JQIIWIpVrJVg 2014/11/22 23:49 Williams

A financial advisor http://www.c5designs.com/about-c5 aldactone price Asked by BBC Radio 4's Media Show if she thought the committee had previously been misled, Hodge said: "We will have to discover that next Monday. Certainly those individuals we are having in front of us don't agree with each other on what happened or who knew what and until we can unravel that we won't know whether or not we were misled."

# xTBLmsrODKuWfqJVsVm 2014/11/22 23:49 Moshe

I'm unemployed http://www.poly.ee/polygon/ order bimatoprost 0.03 The 787 incorporates a raft of changes in the way passengerjets are designed, including greater use of electrical systemsthat save weight compared with older hydraulics. It is the firstpassenger jet built mainly from lightweight carbon-composites.

# abXafyayATwFjE 2014/11/22 23:49 Fredric

I've come to collect a parcel http://threesistersfarmtx.com/about/ where can i buy accutane online without prescription ProFootballFocus.com, which tracks the performance of individual players, has rated Cromartie poorly � 103 out of 104 cornerbacks � thus far this season. The website has Cromartie allowing 22 receptions on 41 targets (53.7% catch rate) for 388 yards and three touchdowns. Opposing quarterbacks have a 110.6 QB rating against him.

# HVvGTkPZUSdoLVXbmm 2014/11/27 7:54 Camila

Whereabouts are you from? http://www.acimps.org/content/blogsection/4/10/ Purchase Oxybutynin In Umbria in Italy, Marco Caprai, head of Arnaldo Capraiwinery, said he expected to harvest about 50 percent more grapesthan last year. He thinks the late harvest will result "in winesthat are not too rich in alcohol and very balanced."

# RGoUVvUCHNoIxvsnQPA 2018/02/18 7:31 Barneyxcq

2oZAvd http://www.LnAJ7K8QSpfMO2wQ8gO.com

タイトル
名前
Url
コメント