比这更优雅的方式 [英] more elegant way than this

查看:79
本文介绍了比这更优雅的方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我有这个功能,下面简单易懂


私有函数ListHeight(byval UserScreenHeight as int)as int

if UserScreenHeight < 1024

返回30

其他

返回50

结束如果

结束功能


这是非常实用的,但对我来说似乎很蹩脚,就像我可以做得更好。

有更多的专业方式或优雅这样做的方法是什么?


Ed

解决方案




私有函数ListHeight(ByVal UserScreenHeight As Integer)整数


返回IIf(UserScreenHeight< 1024,30,50)


结束功能


BTW你不能在VB.Net中使用Int。我是整数或Int16等等


Ged


" Edward W." < ED ****** @ aol.comXSPAMMERIHATEYOU>写在留言中

新闻:uP ************** @ TK2MSFTNGP11.phx.gbl ...

你好,我有这个下面的函数简单易懂

私有函数ListHeight(byval UserScreenHeight as int)as int
如果UserScreenHeight< 1024
返回30
返回50
结束如果
结束功能

它非常实用但对我来说似乎很蹩脚,就像我可以做得更好。
是否有更多的专业方式或优雅怎么做?

Ed



Edward,

你好,我有这个功能,下面简单易懂
它是非常实用的
个人认为所有方法都应该努力的属性!


还有更多"专业"方式或优雅这样做的方法?
只有我会考虑更改的是函数的名称,通常我是

name functions& sub as action statement(动词或动词名词),其中我/ b $ b通常将属性命名为名词。


所以我将函数命名为GetListHeight,as as一个ListHeight函数

表示我正在列出(列表为动词)高度(名词),如果我是

列出高度,我可能会使它复数所以它读取更好...


希望这有帮助

Jay

" Edward W." < ED ****** @ aol.comXSPAMMERIHATEYOU>写在留言中

新闻:uP ************** @ TK2MSFTNGP11.phx.gbl ...你好,我有这个功能,下面简单易行理解私有函数ListHeight(byval UserScreenHeight as int)as int
如果UserScreenHeight< 1024
返回30
返回50
结束如果
结束功能

它非常实用但对我来说似乎很蹩脚,就像我可以做得更好。
是否有更多的专业方式或优雅这样做的方法是什么?

Ed



Ged,

尝试将Option Strict On添加到源文件,你将收到编译

错误。


因为IIf期望对象参数&返回一个对象,你需要一个围绕IIf的
DirectCast,CType或CInt来将返回的值转换回

整数。


希望这有帮助

Jay


" Ged Mead" < GE ********* @ tesco.net>在消息中写道

新闻:uA ************* @ newsfe2-gui.ntli.net ...

怎么样

私有函数ListHeight(ByVal UserScreenHeight As Integer)作为整数

返回IIf(UserScreenHeight< 1024,30,50)
<结束功能

顺便说一句,你不能在VB.Net中使用Int。我是整数或Int16等等.Ged

Edward W. < ED ****** @ aol.comXSPAMMERIHATEYOU>在消息中写道
新闻:uP ************** @ TK2MSFTNGP11.phx.gbl ...

你好,我有这个功能,下面是简单易懂

私有函数ListHeight(byval UserScreenHeight as int)as int
如果UserScreenHeight< 1024
返回30
返回50
结束如果
结束功能

它非常实用但对我来说似乎很蹩脚,就像我能做得更好。
有更多的专业吗?方式或优雅这样做的方式?

blockquote>



hello, I have this function below which is simple and easy to understand

private function ListHeight (byval UserScreenHeight as int) as int
if UserScreenHeight < 1024
return 30
else
return 50
end if
end function

It is very functional but seems pretty lame to me, like I could do better.
is there a more "professional" way or "elegant" way to do this?

Ed

解决方案

How about:

Private Function ListHeight(ByVal UserScreenHeight As Integer) As Integer

Return IIf(UserScreenHeight < 1024, 30, 50)

End Function

BTW you can''t use Int in VB.Net. I thas to be integer or Int16, etc

Ged

"Edward W." <ed******@aol.comXSPAMMERIHATEYOU> wrote in message
news:uP**************@TK2MSFTNGP11.phx.gbl...

hello, I have this function below which is simple and easy to understand

private function ListHeight (byval UserScreenHeight as int) as int
if UserScreenHeight < 1024
return 30
else
return 50
end if
end function

It is very functional but seems pretty lame to me, like I could do better.
is there a more "professional" way or "elegant" way to do this?

Ed



Edward,

hello, I have this function below which is simple and easy to understand
It is very functional Personally those are attributes that all methods should strive for!

is there a more "professional" way or "elegant" way to do this? Only thing I would consider changing is the name of the function, normally I
name functions & sub as action statements (verb or verb noun), where as I
normally name Properties as a noun.

So I would name the function GetListHeight, as a ListHeight function
suggests that I am listing (List as in verb) Height (noun), if I were
listing Height, I would probably make it plural so it reads better...

Hope this helps
Jay
"Edward W." <ed******@aol.comXSPAMMERIHATEYOU> wrote in message
news:uP**************@TK2MSFTNGP11.phx.gbl... hello, I have this function below which is simple and easy to understand

private function ListHeight (byval UserScreenHeight as int) as int
if UserScreenHeight < 1024
return 30
else
return 50
end if
end function

It is very functional but seems pretty lame to me, like I could do better.
is there a more "professional" way or "elegant" way to do this?

Ed



Ged,
Try adding Option Strict On to the source file, you will receive compile
errors.

As IIf expects object parameters & returns an object, you would need a
DirectCast, CType, or CInt around the IIf to cast the value returned back to
Integer.

Hope this helps
Jay

"Ged Mead" <ge*********@tesco.net> wrote in message
news:uA*************@newsfe2-gui.ntli.net...

How about:

Private Function ListHeight(ByVal UserScreenHeight As Integer) As Integer

Return IIf(UserScreenHeight < 1024, 30, 50)

End Function

BTW you can''t use Int in VB.Net. I thas to be integer or Int16, etc

Ged

"Edward W." <ed******@aol.comXSPAMMERIHATEYOU> wrote in message
news:uP**************@TK2MSFTNGP11.phx.gbl...

hello, I have this function below which is simple and easy to understand

private function ListHeight (byval UserScreenHeight as int) as int
if UserScreenHeight < 1024
return 30
else
return 50
end if
end function

It is very functional but seems pretty lame to me, like I could do
better.
is there a more "professional" way or "elegant" way to do this?

Ed




这篇关于比这更优雅的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆