在String类中添加一个函数? [英] Adding a function to the String class?

查看:72
本文介绍了在String类中添加一个函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我写了一个小的ProperCase函数,我想通过我们的公共类库为我们的团队提供




一位同事提到我可以编写一个派生自

String类的新类,在那里添加函数然后我们都会使用新的班级

包含我的功能和所有其他等....听起来比较好

直接...


我的问题是我在创建一个新类后立即想到我需要

a行继承...但是,检查了

String类的文档,当我尝试添加时:


继承System.String


我只是Visual Studio中的一条摆动线....如果我添加它进口

声明它运作良好...


任何人都可以建议我可能做错了...


我的目标是能够做一些喜欢的事情这个:


将myString作为字符串调暗


myString =" HELLO WORLD"


myString = myString.ToProperCase()

Response.Write myString

最终结果将显示为


你好世界

请注意我已经完成了这个功能,只需将它绑成一些东西......任何

帮助赞赏..


问候


Rob

Hi all,

I have written a small ProperCase function which I would like to make
available to our team at work through our common class library.

A colleague mentioned that I could write a new class which derived from the
String class, add the function there and then we would all use the new class
which contained my function and all of the others etc....sounded relatively
straight forward...

My problem is that I figured immediately after creating a new class I''d need
a line that Inherits...however, having check the documentation for the
String class, when I try adding:

Inherits System.String

I just a wiggly line in Visual Studio....If I add it with the Imports
statement it works fine...

Can anyone suggest what I might be doing wrong please...

My aim is to be able to do something like this:

Dim myString as String

myString = "HELLO WORLD"

myString = myString.ToProperCase()

Response.Write myString
The end result will appear as

Hello World
Please note I''ve done the function, just need to tie it into something...any
help appreciated..

Regards

Rob

推荐答案




我的理解是你不想使用import语句并且仍然希望你的字符串类可以工作。 (可能是我错了)


关于我理解的内容,我认为你应该创建一个单独的类

包含你的字符串类的库并尝试添加你在GAC的汇编和

然后尝试一下。


希望有帮助


Rob Meade ;写道:
Hi,

What i understand is that you dont want to use import statement and still
wish that ur string class should work. (May be i am wrong)

With respect to what i Understand,I think you should create a seperate class
library containing your string class and try adding your assembly in GAC and
then give it a try.

Hope that helps

"Rob Meade" wrote:
大家好,

我写了一个小的ProperCase函数,我想通过我们的工作团队为我们的团队提供
公共类库。

一位同事提到我可以写一个派生自
String类的新类,在那里添加函数然后我们都会使用新类
其中包含了我的功能以及所有其他等等....直接听起来比较直接......

我的问题是我在创建新课程后立刻想到了我需要的
一行继承...但是,在我尝试添加时检查了
String类的文档:

继承System.String

我只是Visual Studio中的一条摇摆线......如果我用Imports
语句添加它就可以了。

任何人都可以建议我可能做错了。 ..

我的目标是能够做到这样的事情:

Dim myString a s String

myString =" HELLO WORLD"

myString = myString.ToProperCase()

Response.Write myString

最终结果将显示为

Hello World

请注意我已完成此功能,只需要将其绑定到某个东西......任何
帮助赞赏..

问候

Rob
Hi all,

I have written a small ProperCase function which I would like to make
available to our team at work through our common class library.

A colleague mentioned that I could write a new class which derived from the
String class, add the function there and then we would all use the new class
which contained my function and all of the others etc....sounded relatively
straight forward...

My problem is that I figured immediately after creating a new class I''d need
a line that Inherits...however, having check the documentation for the
String class, when I try adding:

Inherits System.String

I just a wiggly line in Visual Studio....If I add it with the Imports
statement it works fine...

Can anyone suggest what I might be doing wrong please...

My aim is to be able to do something like this:

Dim myString as String

myString = "HELLO WORLD"

myString = myString.ToProperCase()

Response.Write myString
The end result will appear as

Hello World
Please note I''ve done the function, just need to tie it into something...any
help appreciated..

Regards

Rob



Rob,


这个想法对我来说听起来不对。字符串可能是dotnet中最常见的
类。它被用于所有地方的各种场景。要

替换是另一个类只是为了一个小方法???在所有情况下,你是如何使用每个人强制使用新课程的?

此外,你还需要关心打字。可能你应该考虑使用静态方法ProperCase的简单实用程序类将它应用为需要

吗?


Eliyahu


" Rob Meade" < RO ********** @ NOSPAMubht.swest.nhs.uk>在消息中写道

新闻:e7 ************** @ TK2MSFTNGP14.phx.gbl ...
Rob,

The very idea doesn''t sound right to me. String is probably the most common
class in dotnet. It is used in all sorts of scenarios all places around. To
replace is with another class just for the sake of one little method??? How
are you going to enforce using your new class by everyone in all cases?
Also, you will have to care about type casting. May be you should consider
having a simple utility class with static method ProperCase at apply it as
needed?

Eliyahu

"Rob Meade" <ro**********@NOSPAMubht.swest.nhs.uk> wrote in message
news:e7**************@TK2MSFTNGP14.phx.gbl...
大家好,

我写了一个小的ProperCase函数,我希望通过我们的公共类库为我们的团队提供工作。

一位同事提到我可以写一个派生自
String类的新类,在那里添加函数然后我们都会使用包含我的函数和所有其他函数的新的
类....听起来是
相对直截了当......

我的问题是我在创建一个新类后立刻想到我会
需要一行继承...但是,检查了文档
字符串类,当我尝试添加时:

继承System.String

我只是Visual Studio中的一条摆动线....如果我添加它与进口
声明它运作良好......

任何人都可以建议我可能做错了...

我的目标是成为ab le做这样的事情:

将myString变为字符串

myString =" HELLO WORLD"

myString = myString.ToProperCase()

Response.Write myString

最终结果将显示为

Hello World

请注意我已完成功能,只需要把它绑成
的东西......任何帮助都有所帮助..

Rob
Hi all,

I have written a small ProperCase function which I would like to make
available to our team at work through our common class library.

A colleague mentioned that I could write a new class which derived from the String class, add the function there and then we would all use the new class which contained my function and all of the others etc....sounded relatively straight forward...

My problem is that I figured immediately after creating a new class I''d need a line that Inherits...however, having check the documentation for the
String class, when I try adding:

Inherits System.String

I just a wiggly line in Visual Studio....If I add it with the Imports
statement it works fine...

Can anyone suggest what I might be doing wrong please...

My aim is to be able to do something like this:

Dim myString as String

myString = "HELLO WORLD"

myString = myString.ToProperCase()

Response.Write myString
The end result will appear as

Hello World
Please note I''ve done the function, just need to tie it into something...any help appreciated..

Regards

Rob



" Tarun Upadhyaya"写了......
"Tarun Upadhyaya" wrote ...
关于我理解的内容,我认为你应该创建一个包含你的字符串类的单独的类库并尝试添加你的程序集GAC
然后尝试一下。
With respect to what i Understand,I think you should create a seperate
class
library containing your string class and try adding your assembly in GAC
and
then give it a try.




我们已经有一个单独的类库,已经有各种类

及其中的常用功能 - 我们都将其整合到我们的每个

应用程序中。它也已经在GAC中,我的问题就是我如何获得一个包含

String类中所有现有功能的新类,并添加了我自己的类ProperCase方法。


问候


Rob



We have a seperate class library already, which already has various classes
and common functionality in it - we all incorporate this into each of our
applications. It is also already in the GAC, my question is simply how I
get a new class which includes all of the existing functionality from the
String class, and adds my own ProperCase method.

Regards

Rob


这篇关于在String类中添加一个函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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