首页 文章 精选 留言 我的

精选列表

搜索[c 20],共10000篇文章
优秀的个人博客,低调大师

C#中函数的使用

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Demo { class Program { static int MaxValue(int[] intArray) { int maxVal = intArray[0]; for (int i = 1;i<intArray.Length;i++) { if (intArray[i] > maxVal) { maxVal = intArray[i]; } } return maxVal; } static void Main(string[] args) { int[] myArray = { 1, 3, 5, 8, 2, 10, 9, 100, 40 }; int maxVal = MaxValue(myArray); Console.WriteLine("最大值为:{0}",maxVal); Console.ReadKey(); } } } params传参 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Demo { class Program { static int MaxValue(params int[] intArray) { int maxVal = intArray[0]; for (int i = 1;i<intArray.Length;i++) { if (intArray[i] > maxVal) { maxVal = intArray[i]; } } return maxVal; } static void Main(string[] args) { int maxVal = MaxValue(1,3,4,100,200,3); Console.WriteLine("最大值为:{0}",maxVal); Console.ReadKey(); } } } out使用,类似于callback。 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Demo { class Program { static int MaxValue(out int maxIndex,params int[] intArray) { int maxVal = intArray[0]; maxIndex = 0; for (int i = 1;i<intArray.Length;i++) { if (intArray[i] > maxVal) { maxVal = intArray[i]; maxIndex = i; } } return maxVal; } static void Main(string[] args) { int maxIndex; int maxVal = MaxValue(out maxIndex,1,3,4,100,200,3); Console.WriteLine("最大值为:{0}",maxVal); Console.WriteLine("索引为:{0}", maxIndex); Console.ReadKey(); } } } 本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/6728921.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

C#中数组的使用

1.for using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Demo { class Program { static void Main(string[] args) { string[] friendNames = { "张三","李四","王五" }; int i; Console.WriteLine("我有{0}个朋友!",friendNames.Length); for (i = 0;i<friendNames.Length;i++) { Console.WriteLine(friendNames[i]); } Console.ReadKey(); } } } 2.foreach using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Demo { class Program { static void Main(string[] args) { string[] friendNames = { "张三","李四","王五" }; Console.WriteLine("我有{0}个朋友!",friendNames.Length); foreach(string friendName in friendNames) { Console.WriteLine(friendName); } Console.ReadKey(); } } } 本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/6728651.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

C#变量的作用域

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks; namespace Demo{ class Program { static string text; static void Main(string[] args) { int i; //string text=""; for (i=0;i<10;i++) { text = "Line" + Convert.ToString(i); Console.WriteLine("{0}",text); } Console.WriteLine("Last text output in loop:{0}",text); Console.ReadKey(); } } } 本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/6748003.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

C#中的类型转换

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Demo { class Program { static void Main(string[] args) { int val = 97 ; Console.WriteLine( "{0}" ,val); // 97 bool boolVal = Convert.ToBoolean(val); Console.WriteLine( "{0}" , boolVal); // true byte byteVal = Convert.ToByte(val); Console.WriteLine( "{0}" , byteVal); // 97 char charVal = Convert.ToChar(val); Console.WriteLine( "{0}" ,charVal); // a decimal decimalVal = Convert.ToDecimal(val); Console.WriteLine( "{0}" , decimalVal); // 97 double doubleVal = Convert.ToDouble(val); Console.WriteLine( "{0}" , doubleVal); // 97 short shortVal = Convert.ToInt16(val); Console.WriteLine( "{0}" , shortVal); // 97 int intVal = Convert.ToInt32(val); Console.WriteLine( "{0}" , intVal); // 97 long longVal = Convert.ToInt64(val); Console.WriteLine( "{0}" , longVal); // 97 sbyte sbyteVal = Convert.ToSByte(val); Console.WriteLine( "{0}" , sbyteVal); // 97 float floatVal = Convert.ToSingle(val); Console.WriteLine( "{0}" , floatVal); // 97 string stringVal = Convert.ToString(val); Console.WriteLine( "{0}" , stringVal); // 97 ushort ushortVal = Convert.ToUInt16(val); Console.WriteLine( "{0}" , ushortVal); // 97 uint uintVal = Convert.ToUInt32(val); Console.WriteLine( "{0}" , uintVal); // 97 ulong ulongVal = Convert.ToUInt64(val); Console.WriteLine( "{0}" , ulongVal); // 97 Console.ReadKey(); } } } 本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/6728339.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

c++ template归纳学习5

双重模板参数: 我们还是以前几篇中的Stack为例子i:代码如下: template <typename T, template <typename ELEM> class CONT = std::deque > class Stack { private: CONT<T> elems; // elements public: void push(T const&); // push element void pop(); // pop element T top() const; // return top element bool empty() const { // return whether the stack is empty return elems.empty(); } }; 在这段代码中,我们的第二个模板参数修改为:template <typename ELEM> class CONT 和往常一样,你可以使用class替代typename,但是CONT必须是class。 template <typename T, template <class ELEM> class CONT = std::deque> // OK class Stack { … }; but the following is not: template <typename T, template <typename ELEM> typename CONT = std::deque> class Stack { // ERROR … }; 由于上面例子中的ELEM实际中没有用到,其实是可以省略的。 我们实现一个成员函数看看: template <typename T, template <typename> class CONT> void Stack<T,CONT>::push (T const& elem) { elems.push_back(elem); // append copy of passed elem } 但是如果试图使用上面的stack,编译器会说deque不符合CONT的要求,问题在于,std中的deque要求不只是一个参数,第二个参数是一个配置器,他虽然有预设值,但是当它被用来匹配CONT参数的时候,预设值被编译器忽略了。 对于这个问题,我们可以修改,使得CONT参数要求一个带两个参数的容器。 template <typename T, template <typename ELEM, typename ALLOC = std::allocator<ELEM> > class CONT = std::deque> class Stack { private: CONT<T> elems; // elements … }; 最终版本如下: // basics/stack8.hpp #ifndef STACK_HPP #define STACK_HPP #include <deque> #include <stdexcept> #include <allocator> template <typename T, template <typename ELEM, typename = std::allocator<ELEM> > class CONT = std::deque> class Stack { private: CONT<T> elems; // elements public: void push(T const&); // push element void pop(); // pop element T top() const; // return top element bool empty() const { // return whether the stack is empty return elems.empty(); } // assign stack of elements of type T2 template<typename T2, template<typename ELEM2, typename = std::allocator<ELEM2> >class CONT2> Stack<T,CONT>& operator= (Stack<T2,CONT2> const&); }; template <typename T, template <typename,typename> class CONT> void Stack<T,CONT>::push (T const& elem) { elems.push_back(elem); // append copy of passed elem } template<typename T, template <typename,typename> class CONT> void Stack<T,CONT>::pop () { if (elems.empty()) { throw std::out_of_range("Stack<>::pop(): empty stack"); } elems.pop_back(); // remove last element } template <typename T, template <typename,typename> class CONT> T Stack<T,CONT>::top () const { if (elems.empty()) { throw std::out_of_range("Stack<>::top(): empty stack"); } return elems.back(); // return copy of last element } template <typename T, template <typename,typename> class CONT> template <typename T2, template <typename,typename> class CONT2> Stack<T,CONT>& Stack<T,CONT>::operator= (Stack<T2,CONT2> const& op2) { if ((void*)this == (void*)&op2) { // assignment to itself? return *this; } Stack<T2> tmp(op2); // create a copy of the assigned stack elems.clear(); // remove existing elements while (!tmp.empty()) { // copy all elements elems.push_front(tmp.top()); tmp.pop(); } return *this; } #endif // STACK_HPP 测试如下: // basics/stack8test.cpp #include <iostream> #include <string> #include <cstdlib> #include <vector> #include "stack8.hpp" int main() { try { Stack<int> intStack; // stack of ints Stack<float> floatStack; // stack of floats // manipulate int stack intStack.push(42); intStack.push(7); // manipulate float stack floatStack.push(7.7); // assign stacks of different type floatStack = intStack; // print float stack std::cout << floatStack.top() << std::endl; floatStack.pop(); std::cout << floatStack.top() << std::endl; floatStack.pop(); std::cout << floatStack.top() << std::endl; floatStack.pop(); } catch (std::exception const& ex) { std::cerr << "Exception: " << ex.what() << std::endl; } // stack for ints using a vector as an internal container Stack<int,std::vector> vStack; … vStack.push(42); vStack.push(7); std::cout << vStack.top() << std::endl; vStack.pop(); } 程序的输出为: 7 42 Exception: Stack<>::top(): empty stack 7 ============================================================================== 本文转自被遗忘的博客园博客,原文链接:http://www.cnblogs.com/rollenholt/archive/2012/03/08/2384921.html,如需转载请自行联系原作者

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册
修改密码
忘记密码