vb.net一些功能我chaneg在c#那里我发现转换时的问题 [英] vb.net some function i chaneg in c# there i found problem while convert

查看:51
本文介绍了vb.net一些功能我chaneg在c#那里我发现转换时的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public object My_D2sYMD(w_date)
{
	string Ret_Val = null;
	Ret_Val = n2s(Convert.ToDateTime(w_date).Year, 4) + n2s(Convert.ToDateTime(w_date).Month, 2) + n2s(Convert.ToDateTime(w_date).Day, 2);
	return Ret_Val;
}

public object n2s(float w, int n)
{
	string Ret_Val = null;
	Ret_Val = "0000000000" + w;
	Ret_Val = Ret_Val.Substring(Strings.Len(Ret_Val) - n, n);
	return Ret_Val;
}

private object Dt_mdy2ymd(string w_dt)
{
	return w_dt.Substring(6, 4) + w_dt.Substring(0, 2) + w_dt.Substring(3, 2);
}

private object Dt_YMD2DMY(string w_dt)
{
	if (Strings.Len(Strings.Trim(w_dt)) == 8) {
		return w_dt.Substring(6, 2) + "/" + w_dt.Substring(4, 2) + "/" + w_dt.Substring(0, 4);
	} else {
		return "";
	}
}



请检查所有这些功能并提供解决方案,这样我也可以在c#中使用这些功能,使用转换器在c#中转换它们他们给出了一些错误消息,例如


please check all these functions and provide solution so i can use these functions also in c# i convert these in c# using converter but they give some error msg like

Error	1	'System.Linq.Strings' is inaccessible due to its protection level	C:\Users\The Web Soluution\Documents\Visual Studio 2008\WebSites\WebSite2\App_Code\Class1.cs	23	37	C:\...\WebSite2\
Error	2	Operator '+' cannot be applied to operands of type 'object' and 'object'	C:\Users\The Web Soluution\Documents\Visual Studio 2008\WebSites\WebSite2\App_Code\Class1.cs	29	19	C:\...\WebSite2\
Error	3	'System.Linq.Strings' is inaccessible due to its protection level	C:\Users\The Web Soluution\Documents\Visual Studio 2008\WebSites\WebSite2\App_Code\Class1.cs	44	13	C:\...\WebSite2\



pl z尽快提供解决方案





[edit]已添加代码块 - OriginalGriff [/ edit]


plz provide solution as soon as possible


[edit]Code block added - OriginalGriff[/edit]

推荐答案

真的吗?

为什么你在不知道自己在做什么的情况下将这些转换成VB?



我们来看看其中的一部分吗?



Really?
Why did you convert these from VB without knowing what you were doing?

Let's look at some of this, shall we?

public object n2s(float w, int n)
{
    string Ret_Val = null;
    Ret_Val = "0000000000" + w;
    Ret_Val = Ret_Val.Substring(Strings.Len(Ret_Val) - n, n);
    return Ret_Val;
}



1)为什么它返回对象时显然应该返回 string

2)为什么要转换为固定的位数而不检查数字是否实际大于或小于该位数?还是包括一个指数?

3)为什么你要尝试访问Linq?

4)为什么不使用.NET字符串格式?如果你看这里 http://msdn.microsoft.com/en-us /library/dd260048(v=vs.110).aspx [ ^ ]它会告诉你如何正确地做到这一点...



你不能只是拿起旧的(漂亮的垃圾)VB6代码,期望在线翻译把它变成高质量的现代C# - 它不会发生。


1) Why does it return an object when it clearly should return a string?
2) Why are you converting to a fixed number of digits without checking if the number is actually larger or smaller than that number of digits? Or includes an exponent?
3) Why do you try to access Linq at all?
4) Why not just use .NET string formatting? If you look here http://msdn.microsoft.com/en-us/library/dd260048(v=vs.110).aspx[^] it shows you how to do it properly...

You can't just pick up old (pretty rubbish) VB6 code, and expect an online translator to turn it into good quality modern C# - it isn't going to happen.


这篇关于vb.net一些功能我chaneg在c#那里我发现转换时的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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