问:可以继承字符串类型吗? [英] Q: Inherit string type, possible?

查看:67
本文介绍了问:可以继承字符串类型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!


是否可以改变字符串类型?


基本上我想做的就是创建自己的字符串类型。我打电话给它

sqlString,当我使用这个

时,它总会在分配的字符串上使用replace ...


而是使用:


string mystring =" fdfds''fdfd" ;;

mystring.replace("''","''' ');


i想要自动替换当我将值赋给sqlString

类型时。


嗯,希望你能得到我想做的......


问候

马丁

Hi!

Is it possible to alter the string type?

Basicly what i want to do is to create my own string type. lets call it
sqlString, when i use this
it will always use replace on the string assigned...

Instead of using:

string mystring = "fdfds''fdfd";
mystring.replace("''","''''");

i want to do automaticly replace when i assign the value to the sqlString
type.

Hmm, hope you get what i want to do...

Regards
Martin

推荐答案



" Visual Systems AB(Martin Arvidsson)" <毫安************** @ vsab.net>写在

消息新闻:uI ************** @ TK2MSFTNGP09.phx.gbl ...

"Visual Systems AB (Martin Arvidsson)" <ma**************@vsab.net> wrote in
message news:uI**************@TK2MSFTNGP09.phx.gbl...
嗨!

是否可以改变字符串类型?


编号

基本上我想要做的就是创建自己的字符串类型。让我们称之为
sqlString,当我使用它时,它总会在分配的字符串上使用replace ...

而不是使用:

字符串mystring =" fdfds''fdfd" ;;
mystring.replace("''","''''");

我想自动替换时我将值赋给sqlString
类型。
Hi!

Is it possible to alter the string type?

No.
Basicly what i want to do is to create my own string type. lets call it
sqlString, when i use this
it will always use replace on the string assigned...

Instead of using:

string mystring = "fdfds''fdfd";
mystring.replace("''","''''");

i want to do automaticly replace when i assign the value to the sqlString
type.




你最好只创建一个带字符串的单独类型

通过构造函数完成工作,然后通过

重载ToString()来释放字符串。你可以使用隐式转换运算符使它看起来更接近你想要的但是你不能改变字符串本身来做

所以。


更好的是,只需编写一个可以完成工作的实用程序方法,这样就可以编写


string mystring = FormatSqlString(" fdfds''fdfd");


并完成它。



You would be better off just creating a seperate type that takes a string
via a constructor and does the work and then spits the string out by
overloading ToString(). You could use implicit conversion operators to make
it look closer to waht yo uwant, but you can''t change string itself to do
so.

Better yet, just write a utility method that does the work so you can write

string mystring = FormatSqlString("fdfds''fdfd");

and be done with it.


如果你使用参数化命令你会更好。 (无论你是调用

存储过程还是动态sql。)。它为你做了这个替代品以及更多

。 (它会自动阻止sql注入。)和代码维护

会更加轻松。
you would be better if you use parameterized commands. (whether you call
stored procedures or dynamic sql.). it does this replacements and much more
for you. (it prevents sql injection automatically.) and code maintanance
will be much easer.


嗨Martin。

在C#3.0中,您将能够扩展字符串类。

但是,我会使用SqlParameter作为The Crow建议。


快乐选择

- Michael S


" Visual Systems AB(Martin Arvidsson)" <毫安************** @ vsab.net>写在

消息新闻:uI ************** @ TK2MSFTNGP09.phx.gbl ...
Hi Martin.
In C# 3.0 you will be able to extend the string class.
However, I would use SqlParameter as The Crow suggests.

Happy Selecting
- Michael S

"Visual Systems AB (Martin Arvidsson)" <ma**************@vsab.net> wrote in
message news:uI**************@TK2MSFTNGP09.phx.gbl...
嗨!

是否可以改变字符串类型?

基本上我想要做的是创建自己的字符串类型。让我们称之为
sqlString,当我使用它时,它总会在分配的字符串上使用replace ...

而不是使用:

字符串mystring =" fdfds''fdfd" ;;
mystring.replace("''","''''");

我想自动替换时我将值赋给sqlString
类型。

嗯,希望你能得到我想做的......

问候
Martin
Hi!

Is it possible to alter the string type?

Basicly what i want to do is to create my own string type. lets call it
sqlString, when i use this
it will always use replace on the string assigned...

Instead of using:

string mystring = "fdfds''fdfd";
mystring.replace("''","''''");

i want to do automaticly replace when i assign the value to the sqlString
type.

Hmm, hope you get what i want to do...

Regards
Martin



这篇关于问:可以继承字符串类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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