开发者

Assign Values to .Net Property Array with Index Implied

开发者 https://www.devze.com 2023-02-19 01:03 出处:网络
Is it possible to (or how can I) assig开发者_运维知识库n values to a class property array like this:

Is it possible to (or how can I) assig开发者_运维知识库n values to a class property array like this:

MyImgClass.RGB = (255,255,255)

I'm not sure how to build my Public Property setter to allow this, if it's possible at all.


Let's say you have the following property:

Public Class MyImgClass

    Public Property RGB As Integer()

End Class

Then you can do:

myImgClassInstance.RGB = {255,255,255}


You could create a helper method which accepts parameters and builds your object, something like Color.FromArgb. If you do not have source code for the class you can implement it as an extension method.


You would make a 'property bucket' object with those values and assign that to the property.

So, in C# (my apologies, but it should be easy enough to convert to vb)

public MyRGBClass RGB { get; set; }

And then:

MyImgClass.RGB = new MyRGBClass(255, 255, 255);


Can you make RGB an object with 3 properties, red, green, and blue?

0

精彩评论

暂无评论...
验证码 换一张
取 消