杨帆博客

你想开发游戏还是改变世界?


  • 首页

  • 标签

  • 归档

  • 搜索

Different-Ways-to-Add-Parentheses

发表于 2017-12-10 | 更新于: 2018-08-22

  LeetCode#241 Different Ways to Add Parentheses

  Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.

Example 1

Input: "2-1-1".

1
2
((2-1)-1) = 0
(2-(1-1)) = 2

Output: [0, 2]

Example 2

Input: "2*3-4*5"

1
2
3
4
5
(2*(3-(4*5))) = -34
((2*3)-(4*5)) = -14
((2*(3-4))*5) = -10
(2*((3-4)*5)) = -10
(((2*3)-4)*5) = 10

Output: [-34, -14, -10, -10, 10]

阅读全文 »

CSharp篇-伍

发表于 2017-05-06 | 更新于: 2018-08-22

.NET Core Web Api 快速入手 —— C#篇 [ 伍 ]

本篇内容

C# 数据库使用


  C#使用数据库的方式大体上有两种,ado 和 ef 模型,在我们的项目中使用了传统的 ado ,所以对于 ef 模型暂且不提。

  ado.net提供了丰富的数据库操作,这些操作可以分为三个步骤:

  • 第一,使用SqlConnection对象连接数据库;
  • 第二,建立SqlCommand对象,负责SQL语句的执行和存储过程的调用;
  • 第三,对SQL或存储过程执行后返回的“结果”进行操作。

  对返回“结果”的操作可以分为两类:

  • 一是用SqlDataReader直接一行一行的读取数据集;
  • 二是DataSet联合SqlDataAdapter来操作数据库。

  两者比较:

阅读全文 »

CSharp篇-肆

发表于 2017-05-05 | 更新于: 2018-08-22

.NET Core Web Api 快速入手 —— C#篇 [ 肆 ]

本篇内容

using关键字

Attribute


  1. using关键字

    using一般有着以下几种用法:

    • using System。
        这个是最常用的,就是using+命名空间,这样就可以直接使用命名空间中的类型,而免去了使用详细的命名空间

    • using别名。
        using + 别名 = 包括详细命名空间信息的具体的类型。例如我们用以下语句引入System.IO.Compression命名空间:
      using Zip=System.IO.Compression;这时我们就可以用Zip表示System.IO.Compression命名空间,使用Zip.GZipStream就是使用System.IO.Compression.GZipStream。给程序书写带来方便。

      阅读全文 »

CSharp篇-叁

发表于 2017-05-03 | 更新于: 2018-08-22

.NET Core Web Api 快速入手 —— C#篇 [ 叁 ]

本篇内容

静态方法与静态字段

命名空间


  1. 静态方法与静态字段

      在GitHub上我的TTMS WebApi项目中, Servers文件夹中是具体的数据库操作。所有的方法都使用static静态方法。在Server.cs文件中使用了static存储全局的数据库连接字符串。

    • 静态方法

        静态方法可以被重载但不能被重写,因为它们属于类,不属于类的任何实例。

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      /// <summary>
      /// 登陆
      /// </summary>
      /// <returns>登陆结果</returns>
      /// <param name="account">账号</param>
      /// <param name="password">密码</param>
      public static object Login(string account, string password)
      {
      using (var con = new SqlConnection(Server.SqlConString))
      {
      con.Open();

      var sqlCom = new SqlCommand("sp_login", con)
      {
      CommandType = CommandType.StoredProcedure
      };

      sqlCom.Parameters.Add(new SqlParameter
      {
      ParameterName = "@account",
      Direction = ParameterDirection.Input,
      SqlDbType = SqlDbType.NVarChar,
      Size = 15,
      Value = account
      });
      sqlCom.Parameters.Add(new SqlParameter
      {
      ParameterName = "@password",
      Direction = ParameterDirection.Input,
      SqlDbType = SqlDbType.NVarChar,
      Size = 15,
      Value = password
      });
      sqlCom.Parameters.Add(new SqlParameter
      {
      ParameterName = "@return",
      Direction = ParameterDirection.ReturnValue,
      SqlDbType = SqlDbType.Int
      });

      sqlCom.ExecuteNonQuery();

      return sqlCom.Parameters["@return"].Value;
      }
      }
      阅读全文 »

CSharp篇-贰

发表于 2017-05-02 | 更新于: 2018-08-22

.NET Core Web Api 快速入手 —— C#篇 [ 贰 ]

本篇内容

类基础

  1. 类

  “类”是一种构造,通过使用该构造,您可以将其他类型的变量、方法和事件组合在一起,从而创建自己的自定义类型。 类就像一个蓝图, 它定义类型的数据和行为。 如果类没有声明为静态类,客户端代码就可以创建赋给变量的“对象”或“实例”,从而使用该类。 在对变量的所有引用都超出范围之前,该变量始终保持在内存中。 所有引用都超出范围时,CLR 将标记该变量以供垃圾回收。 如果类声明为静态类,则内存中只存在一个副本,并且客户端代码只能通过该类自身而不是“实例变量”访问该类。 有关更多信息,请参见静态类和静态类成员。

  • C#类的声明

    1
    2
    3
    4
    public class ClassName
    {
    //Fields, properties, methods and events go here...
    }
  • C# Struct [ 未使用 , 仅介绍 ]

    阅读全文 »
1…444546
KsGin

KsGin

游戏程序员/计算机图形学/Unity/西山居搬砖

226 日志
16 标签
GitHub E-Mail Google Twitter
© 2018 KsGin @ 2018
0%