移动超出流量计算方法 小龙卡省外流量怎么算的?

扫二维码下载作业帮
拍照搜题,秒出答案,一键查看所有搜题记录
下载作业帮安装包
扫二维码下载作业帮
拍照搜题,秒出答案,一键查看所有搜题记录
C#编写一个应用程序,完成从1开始加到n的求和计算。程序步骤:a. 提示用户输入一个50至100之间的数字,输入0退出。b. 用户输入的值小于50或大于100时,提示出错,要求用户重新输入。c. 用户输入正确时,打印结果。重复进入a步骤。提示:a. 编写一个方法完成计算功能,返回结果值。b. 使用for循环完成求和计算。c. 使用while循环判断程序是否退出。d. 使用if…else…来判断用户输入是否符合要求。可以使用break跳出while循环。
扫二维码下载作业帮
拍照搜题,秒出答案,一键查看所有搜题记录
关键代码:while&(true){&&&Console.WriteLine(&请输入一个50至100之间的数字:&);&&&string&input&=&Console.ReadLine();&&&int&value&=&0;&&&if&(!int.TryParse(input,&out&value))&&&{&&&&&&Console.WriteLine(&只能输入数字,请重新输入。&);&&&&&&&&&}&&&&if&(value&==&0)&&&{&&&&&&&&&}&&&else&if&(value&&&50&||&value&&&100)&&&{&&&&&&Console.WriteLine(&不在范围内,请重新输入。&);&&&&&&&&&}&&&&int&sum&=&0;&&&for&(int&i&=&1;&i&&=&&i&++)&&&{&&&&&&sum&+=&i;&&&}&&&Console.WriteLine(&结果为:&&+&sum.ToString());}&Console.WriteLine(&程序已退出&);
为您推荐:
扫描下载二维码C# OpenFileDialog.ShowDialog 打不开,程序无响应(错误的解决)
我的图书馆
C# OpenFileDialog.ShowDialog 打不开,程序无响应(错误的解决)
1:C# OpenFileDialog.ShowDialog 打不开,程序无响应
环境:win7 .Net framework2.0
现象; c#写的一个程序,在xp下点击文件打开按钮没有任何问题,但在我的win7下,点击则不弹出打开文件对话框,程序忙且无响应
网上搜索其他人也出现过这样的问题,且有些计算机行有些不行。
给出解决办法为设置openFileDialog打开的缺省目录。
可是设置了后仍然不行,在win7下,点击打开无法弹出打开文件对话框且程序忙,无响应
继续搜索,发现一个帖子也是说这个问题,大致是主线程必须是单线程单元,否则可能会导致此问题,应在主线程上加 [STAThread] 属性
更改main函数的声明如下,问题解决。
[STAThread]
public static void Main(string[] args)
网上找到的关于[STAThread]的一些说明:
[STAThread]
STAThread:Single&&&& Thread&&&& Apartment Thread.(单一线程单元线程)
[]是用来表示Attributes;
[STAThread]
是一种线程模型,用在程序的入口方法上(在C#和VB.NET里是Main()方法),来指定当前线程的ApartmentState 是STA。用在其他方法上不产生影响。在aspx页面上可以使用AspCompat = "true" 来达到同样的效果。这个属性只在& Com& Interop& 有用,如果全部是& managed& code& 则无用。简单的说法:[STAThread]指示应用程序的默认线程模型是单线程单元 (STA)。启动线程模型可设置为单线程单元或多线程单元。如果未对其进行设置,则该线程不被初始化。也就是说如果你用的.NET
Framework,并且没有使用COM Interop,一般不需要这个Attribute。其它的还有MTA(多线程套间)、Free& Thread(自由线程)。
[STAThread] attribute指示应用程序的 COM 线程模型是单线程单元。
而于此对应的多线程单元则是 [MTAThread] (多线程单元线程)
COM 线程模型只适用于使用 COM interop 的应用程序。如果将此属性应用到不使用 COM interop 的应用程序,将没有任何效果。
COM 线程模型可设置为单线程单元或多线程单元。如果应用程序线程实际调用了 COM 组件,则仅为 COM interop 初始化该线程。如果没有使用 COM interop,则不初始化该线程。
我又在网络上找了两篇文章或许更能说明这个问题。我没有翻译,文章的大意是,由于很多COM在.NET环境下如果使用多线程的话,会导致引用的COM不能正常运行,而如果不声明程序为STAThread的话,.NET就会自动使用多线程来提高效率,这样就会导致不可预知的后果。
Q. When I create a c# project from scratch in VS.NET, the generated code always have a [STAThread] attribute above the main routine. What does the STAThread attribute really do? Can I change it to MTAThread instead? I have searched website and books, no
one seems to explain this well.
Asked by anon. Answered by the Wonk on February 17, 2003
The STAThreadAttribute marks a thread to use the Single-Threaded COM Apartment if COM is needed. By default, .NET won't initialize COM at all. It's only when COM is needed, like when a COM object or COM Control is created or when drag 'n' drop is needed,
that COM is initialized. When that happens, .NET calls the underlying CoInitializeEx function, which takes a flag indicating whether to join the thread to a multi-threaded or single-threaded apartment.
A multi-threaded apartment (MTA) in COM is more efficient, since any of a number of RPC threads from a pool can be used to handle a request. However, an object on the MTA thread needs to protect itself from multiple threads accessing it at the same time,
so that efficiency comes at a cost.
The single-thread apartment (STA) in COM is inherently single-threaded and therefore no additional thread synchronization is needed. The STA is implemented using the thread's Windows message queue, which is how requests to objects on an STA are serialized.
Because of how the STA thread is implemented, calls to objects on that thread are serialized with Windows message handling on that thread, making sure that everything, both the COM objects and the underlying windowing objects, e.g. HWNDs, are all synchronized.
This is necessary for UI-oriented COM objects, like controls and drag 'n' drop, which must also be synchronized together with the UI.
When COM is needed .NET will call CoInitializeEx, picking the MTA by default because it's more efficient. However, to get the synchronization needed for controls, windows and drag 'n' drop, you need to mark a thread's entry point with the STAThreadAttribute
to let .NET know to initialize the UI thread on the STA. All of the VS.NET project templates put that attribute in to make sure you don't forget:
[STAThread]
static void Main() {...}
Be very careful to leave that STAThreadAttribute just where it is, or things can go all wacky and you won't know why.
Original Source Link:
2:ShowDialog() 错误的解决
首先,一个类里,有个linkLabel1
private OpenFileDialog openFileDialog1;
private DialogR
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
&&&&&&&&&&& openFileDialog1 = new OpenFileDialog();
&&&&&&&&&&& string patch = Application.StartupPath + "";
&&&&&&&&&&& openFileDialog1.InitialDirectory =
&&&&&&&&&&& openFileDialog1.Filter = "xls files (*.xls)|*.xls";
&&&&&&&&&&&&result = openFileDialog1.ShowDialog();
&&&&&&&&&&& if (result == DialogResult.OK)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& if (openFileDialog1.FileName != "")
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& Process.Start(openFileDialog1.FileName);
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&&
&&&&&&&&&&& }
&&&&&&&&&&&
在可以调用 OLE 之前,必须将当前线程设置为单线程单元(STA)模式。请确保您的 Main 函数带有 STAThreadAttribute 标记。 只有将调试器附加到该进程才会引发此异常。
在测试小程序里没有问题,当移到大程序里就这样的问题了。可能是线程多的原因。解决办法就是添加线程,代码如下
private Thread invokeT
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
&&&&&&&&&&& openFileDialog1 = new OpenFileDialog();
&&&&&&&&&&& openFileDialog1.InitialDirectory =
&&&&&&&&&&& openFileDialog1.Filter = "xls files (*.xls)|*.xls";
&&&&&&&&&&& invokeThread = new Thread(new ThreadStart(InvokeMethod));
&&&&&&&&&&& invokeThread.SetApartmentState(ApartmentState.STA);
&&&&&&&&&&& invokeThread.Start();
&&&&&&&&&&& invokeThread.Join();
&&&&&&&&&&& if (result == DialogResult.OK)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& if (openFileDialog1.FileName != "")
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& Process.Start(openFileDialog1.FileName);
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
private void InvokeMethod()
&&&&&&&&&&& result = openFileDialog1.ShowDialog();
问题得到解决
TA的最新馆藏[转]&[转]&[转]&[转]&[转]&[转]&
喜欢该文的人也喜欢Service Unavailable运行程序提示异常,创建microsoft.scripting的配置节处理程序时出错,未能加载文件或程序集,microsoft.scripting,version=
有关调用实时(JIT)调试而不是此对话框的详细信息,
请参见此消息的结尾。
**************&异常文本&**************
System.Configuration.ConfigurationErrorsException:&创建&microsoft.scripting&的配置节处理程序时出错:&未能加载文件或程序集“Microsoft.Scripting,&Version=1.1.1.10,&Culture=neutral,&PublicKeyToken=null”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。&(异常来自&HRESULT:0x)&(d:\文档\visual&studio&2010\Projects\PY\PY\bin\Debug\PY.exe.Config&line&3)&---&&System.IO.FileLoadException:&未能加载文件或程序集“Microsoft.Scripting,&Version=1.1.1.10,&Culture=neutral,&PublicKeyToken=null”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。&(异常来自&HRESULT:0x)
&&&在&System.Configuration.TypeUtil.GetTypeWithReflectionPermission(IInternalConfigHost&host,&String&typeString,&Boolean&throwOnError)
&&&在&System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.Init(RuntimeConfigurationRecord&configRecord,&FactoryRecord&factoryRecord)
&&&在&System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.InitWithRestrictedPermissions(RuntimeConfigurationRecord&configRecord,&FactoryRecord&factoryRecord)
&&&在&System.Configuration.RuntimeConfigurationRecord.CreateSectionFactory(FactoryRecord&factoryRecord)
&&&在&System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(String&configKey,&Boolean&&isRootDeclaredHere)
&&&---&内部异常堆栈跟踪的结尾&---
&&&在&System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(String&configKey,&Boolean&&isRootDeclaredHere)
&&&在&System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String&configKey,&Boolean&getLkg,&Boolean&checkPermission,&Boolean&getRuntimeObject,&Boolean&requestIsHere,&Object&&result,&Object&&resultRuntimeObject)
&&&在&System.Configuration.BaseConfigurationRecord.GetSection(String&configKey)
&&&在&System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String&sectionName)
&&&在&System.Configuration.ConfigurationManager.GetSection(String&sectionName)
&&&在&Microsoft.Scripting.Hosting.Configuration.Section.LoadRuntimeSetup(ScriptRuntimeSetup&setup,&Stream&configFileStream)
&&&在&Microsoft.Scripting.Hosting.ScriptRuntime.CreateFromConfiguration()
&&&在&PY.Form1.button1_Click1(Object&sender,&EventArgs&e)&位置&d:\文档\visual&studio&2010\Projects\PY\PY\Form1.cs:行号&37
&&&在&System.Windows.Forms.Control.OnClick(EventArgs&e)
&&&在&System.Windows.Forms.Button.OnClick(EventArgs&e)
&&&在&System.Windows.Forms.Button.OnMouseUp(MouseEventArgs&mevent)
&&&在&System.Windows.Forms.Control.WmMouseUp(Message&&m,&MouseButtons&button,&Int32&clicks)
&&&在&System.Windows.Forms.Control.WndProc(Message&&m)
&&&在&System.Windows.Forms.ButtonBase.WndProc(Message&&m)
&&&在&System.Windows.Forms.Button.WndProc(Message&&m)
&&&在&System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&&m)
&&&在&System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&&m)
&&&在&System.Windows.Forms.NativeWindow.Callback(IntPtr&hWnd,&Int32&msg,&IntPtr&wparam,&IntPtr&lparam)
**************&已加载的程序集&**************
&&&&程序集版本:&4.0.0.0
&&&&Win32&版本:&4.0.&built&by:&FX45RTMGDR
&&&&基本代码:&file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
&&&&程序集版本:&1.0.0.0
&&&&Win32&版本:&1.0.0.0
&&&&基本代码:&file:///d:/%E6%96%87%E6%A1%A3/visual%20studio%202010/Projects/PY/PY/bin/Debug/PY.exe
----------------------------------------
System.Windows.Forms
&&&&程序集版本:&4.0.0.0
&&&&Win32&版本:&4.0.&built&by:&FX45RTMGDR
&&&&基本代码:&file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c/System.Windows.Forms.dll
----------------------------------------
System.Drawing
&&&&程序集版本:&4.0.0.0
&&&&Win32&版本:&4.0.&built&by:&FX45RTMGDR
&&&&基本代码:&file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
&&&&程序集版本:&4.0.0.0
&&&&Win32&版本:&4.0.&built&by:&FX45RTMGDR
&&&&基本代码:&file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c/System.dll
----------------------------------------
System.Configuration
&&&&程序集版本:&4.0.0.0
&&&&Win32&版本:&4.0.&built&by:&FX45RTMGDR
&&&&基本代码:&file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
&&&&程序集版本:&4.0.0.0
&&&&Win32&版本:&4.0.&built&by:&FX45RTMGDR
&&&&基本代码:&file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c/System.Xml.dll
----------------------------------------
Microsoft.Scripting
&&&&程序集版本:&1.0.0.0
&&&&Win32&版本:&2.6.1003.1
&&&&基本代码:&file:///d:/%E6%96%87%E6%A1%A3/visual%20studio%202010/Projects/PY/PY/bin/Debug/Microsoft.Scripting.DLL
----------------------------------------
System.Core
&&&&程序集版本:&4.0.0.0
&&&&Win32&版本:&4.0.&built&by:&FX45RTMREL
&&&&基本代码:&file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c/System.Core.dll
----------------------------------------
Microsoft.CSharp
&&&&程序集版本:&4.0.0.0
&&&&Win32&版本:&4.0.
&&&&基本代码:&file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.CSharp/v4.0_4.0.0.0__b03f5f7f11d50a3a/Microsoft.CSharp.dll
----------------------------------------
System.Configuration.resources
&&&&程序集版本:&4.0.0.0
&&&&Win32&版本:&4.0.30319.1&(RTMRel.0)
&&&&基本代码:&file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration.resources/v4.0_4.0.0.0_zh-Hans_b03f5f7f11d50a3a/System.Configuration.resources.dll
----------------------------------------
System.Windows.Forms.resources
&&&&程序集版本:&4.0.0.0
&&&&Win32&版本:&4.0.30319.1&built&by:&RTMRel
&&&&基本代码:&file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms.resources/v4.0_4.0.0.0_zh-Hans_b77a5c/System.Windows.Forms.resources.dll
----------------------------------------
mscorlib.resources
&&&&程序集版本:&4.0.0.0
&&&&Win32&版本:&4.0.30319.1&(RTMRel.0)
&&&&基本代码:&file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/mscorlib.resources/v4.0_4.0.0.0_zh-Hans_b77a5c/mscorlib.resources.dll
----------------------------------------
**************&JIT&调试&**************
要启用实时(JIT)调试,
该应用程序或计算机的&.config&文件(machine.config)的&system.windows.forms&节中必须设置
jitDebugging&值。
编译应用程序时还必须启用
&configuration&
&&&&&system.windows.forms&jitDebugging=&true&&/&
&/configuration&
启用&JIT&调试后,任何未经处理的异常
都将被发送到在此计算机上注册的&JIT&调试器,
而不是由此对话框处理。
-----------------------------------------------------------------------------------------内容是
using&System.Collections.G
using&ponentM
using&System.D
using&System.D
using&System.L
using&System.T
using&System.Windows.F
using&Microsoft.Scripting.H
using&IronPython.H
using&System.Runtime.InteropS
namespace&PY
&&&&public&partial&class&Form1&:&Form
&&&&&&&&public&Form1()
&&&&&&&&&&&&InitializeComponent();
&&&&&&&&private&void&label1_Click(object&sender,&EventArgs&e)
&&&&&&&&private&void&button1_Click1(object&sender,&EventArgs&e)
&&&&&&&&&&&&string&scriptToU
&&&&&&&&&&&&if&(radioButton1.Checked)
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&scriptToUse&=&&AmountDisc.py&;
&&&&&&&&&&&&}
&&&&&&&&&&&&else
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&scriptToUse&=&&CountDisc.py&;
&&&&&&&&&&&&}
&&&&&&&&&&&&ScriptRuntime&scriptRuntime&=&ScriptRuntime.CreateFromConfiguration();
&&&&&&&&&&&&ScriptEngine&pythEng&=&scriptRuntime.GetEngine(&Python&);
&&&&&&&&&&&&ScriptSource&source&=&pythEng.CreateScriptSourceFromFile(scriptToUse);
&&&&&&&&&&&&ScriptScope&scope&=&pythEng.CreateScope();
&&&&&&&&&&&&scope.SetVariable(&prodCount&,&Convert.ToInt32(textBox1.Text));
&&&&&&&&&&&&scope.SetVariable(&amt&,&Convert.ToDecimal(textBox2.Text));
&&&&&&&&&&&&source.Execute(scope);
&&&&&&&&&&&&label1.Text&=&scope.GetVariable(&retAmt&).ToString();
&&&&&&&&private&void&radioButton1_CheckedChanged(object&sender,&EventArgs&e)
&&&&&&&&private&void&textBox1_TextChanged(object&sender,&EventArgs&e)
&&&&&&&&private&void&textBox2_TextChanged(object&sender,&EventArgs&e)
&&&&&&&&private&void&label3_Click(object&sender,&EventArgs&e)
&&&&&&&&private&void&label3_Click_1(object&sender,&EventArgs&e)
&&&&&&&&private&void&textBox1_TextChanged_1(object&sender,&EventArgs&e)
回复讨论(解决方案)
看提示信息,应该是System.Configuration相关程序集版本不兼容,
建议在检查下引用的程序集
再看看选择的目标framework是否正确
Scripting.dll文件版本不一样,载不到书上那个版本的啊,有没有什么办法!
有哪位大大知道是什么原因吗
Scripting.dll文件用同一个版本的也试了下一样出这问题
没分了,发不了贴,借楼主帖子问个问题,请大神帮忙转个函数
&&&&&var&path&=&&[,9M,L&,H;,H@,L;,IK,IM,L=,?7,HH,L&,@I,@&,9M,L&,HJ,HJ9@,L?,HM,@K,9M&,
&&&&&&&&ids&=&172337,
&&&&&&&&codepath&=&&&;
&&&&function&strcode(path,&id){
&&&&&&&&var&href&=&&&;
&&&&&&&&href&=&path.replace(/./g,function(a){
&&&&&&&&&&&&return&String.fromCharCode(&a.charCodeAt(0)&-&id&%&10&);
&&&&&&&&});
&&&&&&&&return&
&&&&codepath&=&strcode(&path,&ids&);
&&&&alert(&codepath&)
红色这段是将上面的path和ids带入后,解密成一个新的字符窜,求大侠转成c#方法,在winform使用,谢谢!
创建&microsoft.scripting&的配置节处理程序时出错:&未能加载文件或程序集“Microsoft.Scripting,&Version=0.9.6.10,&Culture=neutral,&PublicKeyToken=null”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。&(异常来自&HRESULT:0x)用文本提供的源代码运行后也是这问题,这到底是什么问题引起的呢,请各位师傅提个醒!
5楼的问题,我自己搞定了,无需劳烦大家了
&private&void&button5_Click(object&sender,&EventArgs&e)
&&&&&&&&&&&&String&dcode&=&&K&3G&F7&:F&92&F:&CC&:2&F8&:B&95&F6&C9&94&F5&CD&B7&F6&C9&9D&F6&C1&:5&F8&9:&C:&3G&F8&BD&BD232&F9&BG&:E&3G&;
&&&&&&&&&&&&int&id&=&172621;
&&&&&&&&&&&&String&tmpstr&=&String.E
&&&&&&&&&&&&String&dcode1&=&String.E
&&&&&&&&&&&&for&(int&i&=&0;&i&&&dcode.L&i++)&
&&&&&&&&&&&&{&
&&&&&&&&&&&&&&&&tmpstr&=&dcode.Substring(i,&1);&
&&&&&&&&&&&&&&&&dcode1&=&dcode1&+&((char)(tmpstr[0]&-&id&%&10)).ToString();&
&&&&&&&&&&&&}
&&&&&&&&&&&&MessageBox.Show(dcode1);
没人知道哪里出问题了吗?
创建&microsoft.scripting&的配置节处理程序时出错:&未能加载文件或程序集“Microsoft.Scripting,&Version=0.9.6.10,&Culture=neutral,&PublicKeyToken=null”求大神们帮忙啊!谢谢了C#中实现MDI_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
C#中实现MDI
上传于|0|0|文档简介
&&C#中实现MDI
你可能喜欢

我要回帖

更多关于 移动超过流量怎么算 的文章

 

随机推荐