【c#-解决asp.net中“潜在危险请求”错误的最佳方法是什么?】教程文章相关的互联网学习教程文章

C#基础——静态变量和静态方法【代码】

静态变量和静态方法都必须通过类名来引用。 简单使用示例 using System;class StaticVar {public int x;public static int y;public void PrintInfo(){Console.WriteLine("非静态变量x={0}",x);Console.WriteLine("静态变量y = {0}",y);} } class Test {static void Main(string[] args){StaticVar stv = new StaticVar();stv.x = 10;// stv.y = 20; //error;无法使用实例引用访问静态成员“StaticVar.y”;改用类型名来限定它Stat...

(精华)2020年6月27日 C#类库 string(扩展方法)【代码】

using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Globalization; using System.Linq; using System.Net; using System.Reflection; using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; using System.Xml;namespace Core.Util {public static partial class Extention{/// <summary>/// 转为bo...

(精华)2020年6月26日 C#类库 Enum(扩展方法)【代码】

using System; using System.ComponentModel; using System.Linq;namespace Core.Util {/// <summary>/// 拓展类/// </summary>public static partial class Extention{/// <summary>/// 获取枚举描述/// </summary>/// <param name="value">枚举值</param>/// <returns></returns>public static string GetDescription(this Enum value){DescriptionAttribute attribute = value.GetType().GetField(value.ToString()).GetCustomA...

C#中几种循环的方法和他们的不同点(简述)

我们在使用时可以按照方便程度来用~ ① while循环 while循环通常用于不确定的循环次数时去使用它 ② do...while循环 功能上和while基本类似,不同之处它保证了循环至少执行一次 ③ for 循环 for循环主要用于循环次数固定的循环 ④ foreach循环 是一种十分高效的循环,主要用来遍历IEnumerable的容器类型,比如ArrayList、List等都可以使用。

C#基础难委托之模板方法【代码】

using System; namespace ConsoleTese {class Program{public delegate int dele(int a, int b);static void Main(string[] args){ProductFactory productFactory = new ProductFactory();WrapFation wrapFation = new WrapFation();Func<Product> func = new Func<Product>(productFactory.MakePizza);Func<Product> func1 = new Func<Product>(productFactory.MakeToyCar);Box box= wrapFation.WrapProduct(func);Box box1=wrapF...

c#关于chart控件的使用方法【代码】

经过一段时间的学习掌握了调整chart控件的相关代码public class ChartHelper{/// <summary>/// Name:添加序列/// </summary>/// <param name="chart">图表对象</param>/// <param name="seriesName">序列名称</param>/// <param name="chartType">图表类型</param>/// <param name="color">颜色</param>/// <param name="markColor">标记点颜色</param>/// <param name="showValue">是否显示数值</param>public static void AddSe...

C#委托方法的使用(含例子)【代码】

C#委托1、概念1.1、委托是什么1.2、怎么调用委托1.3、优点2、语法2.1、委托的声明2.2、委托的使用3、举例3.1、先定义一个委托类型3.2、定义数个委托方法和一个通用方法3.3、控制台输出 1、概念 1.1、委托是什么委托是一种引用类型,它表示对具有特定参数列表和返回类型的方法的引用。1.2、怎么调用委托可以通过委托实例调用方法,也可以使用委托将方法作为参数传递给其他方法。1.3、优点在.NET开发活动中,如编写架构级代码,委托的...

C#表达式体方法 (expression-bodied method ) - 0023

如果方法的实现只有一条语句,可以使用一个简化的语法:表达式体方法。 列如方法:public bool IsSquare(Rectangle rect) {return (rect.Height == rect.Width); } 和:public int Sum(int x, int y) {return x + y; }可以写成:public bool IsSquare(Rectangle rect) => rect.Height == rect.Width; 和:public int Sum(int x, int y) => x + y;注意:不需要写花括号和return关键字 使用运算符=>区分左边的声明和右边的实现 右边代码...

C# HttpPost 【ContentType:multipart/form-data】表单提交数据方法

var postContent = new MultipartFormDataContent(); postContent.Headers.Add("ContentType", $"multipart/form-data"); //这是【string : string】的键值对 postContent.Add(new StringContent(appConfig.apiName), "api_name"); //这是【string : Json】的键值对;param是一个类的对象 postContent.Add(new StringContent(param.ToJsonStr()), "content"); //form表单格式传参 string result = ""; strin...

C#中通过list的GetRange方法对list进行按执行长度截取并拆分【代码】【图】

场景 假如一个list有235万条记录,现在需要每50万条记录生成一个文件,怎样拆分并截取。 注: 博客主页: https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程序猿 获取编程相关电子书、教程推送与免费下载。 实现 首先需要获取总共的需要拆分的文件的个数,通过将list的总长度对指定每个文件的个数进行求余进而决定要拆分的文件的个数。int excelTotalCount = RecordDataList.Count % eachExcelCount == 0 ? (RecordD...

C#实现对DropDowList添加下拉选项的方法【代码】

C#实现对DropDowList添加下拉选项的方法 1.在指定下标处添加:DropDownList.Items.Insert(2, new ListItem("Title", "Value"));2.在已存在的选择下添加: DropDownList.Items.Add(new ListItem("Title", "Value"));DropDownList.Items.Add("Value");3.在某个控件里面添加: ((DropDownList)wfvMaster.FindControl("DropDownList1")).Items.Add("Value");

C# Winform界面不能适配高DPI的解决方法

1. 将 Form 的 AutoScaleMode 属性设置为 DPI; 2. 在Program.cs中修改代码class Program {[STAThread]static void Main(){if (Environment.OSVersion.Version.Major >= 6)SetProcessDPIAware();Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);Application.Run(new Form1());}[System.Runtime.InteropServices.DllImport("user32.dll")]private static extern bool SetProcessDPIAware()...

C# Winform 跨线程更新UI控件常用方法汇总【代码】

本文转载自:https://www.cnblogs.com/marshal-m/p/3201051.html 概述 C#Winform编程中,跨线程直接更新UI控件的做法是不正确的,会时常出现“线程间操作无效: 从不是创建控件的线程访问它”的异常。处理跨线程更新Winform UI控件常用的方法有4种:1. 通过UI线程的SynchronizationContext的Post/Send方法更新;2. 通过UI控件的Invoke/BeginInvoke方法更新; 3. 通过BackgroundWorker取代Thread执行异步操作;4. 通过设置窗体属性,...

C#方法中的几种参数传递

参数传递 以下为从菜鸟教程中学习记下的笔记 1、按值传递参数 这种方式复制参数的实际值给函数的形式参数,实参和形参使用的是两个不同内存中的值。在这种情况下,当形参的值发生改变时,不会影响实参的值,从而保证了实参数据的安全。 例子: //定义一个值传递的方法public void swap(int x,int y){}//调用的时候xxx.swap(a,b);? 2、按引用传递参数 引用参数是一个对变量的内存位置的引用。当按引用传递参数时,与值参数不同的是,...

总结C#获取当前路径的7种方法

C#获取当前路径的方法如下:1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName-获取模块的完整路径。e799bee5baa6e4b893e5b19e313333376234622. System.Environment.CurrentDirectory-获取和设置当前目录(该进程从中启动的目录)的完全限定目录。3. System.IO.Directory.GetCurrentDirectory()-获取应用程序的当前工作目录。这个不一定是程序从中启动的目录啊,有可能程序放在C:\www里,这个函数有可能返回...

错误 - 相关标签