C#中怎么样将string类型转化为tinyint类型
3个回答
展开全部
SQL SERVER中的tinyint类型为从 0 到 255 的整型数据,存储大小为 1 字节。
.NET中C#的byte关键字映射.NET的Byte 结构,表示一个 8 位无符号整数,Byte 值类型表示值介于 0 和 255 之间的无符号整数。
所以相当于C#中的byte类型,把string类型先转换成byte就可以当作tinyint使用。代码如下:
string str="123";
byte tin = Convert.ToByte(str);
//然后把tin直接赋值给tinyint类型字段
.NET中C#的byte关键字映射.NET的Byte 结构,表示一个 8 位无符号整数,Byte 值类型表示值介于 0 和 255 之间的无符号整数。
所以相当于C#中的byte类型,把string类型先转换成byte就可以当作tinyint使用。代码如下:
string str="123";
byte tin = Convert.ToByte(str);
//然后把tin直接赋值给tinyint类型字段
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace baidu
{
class temp
{
public static void main()
{
string s = "25";
s.ToTinyInt().show();
}
}
public static class MyExtensions
{
public static string sort(this string temp)
{
return temp.convert2int().sort().convert2chararray().CharToString();
}
public static string CharToString(this char[] temp)
{
string s = "";
for (int i = 0; i < temp.Length; i++)
{
s += temp[i].ToString();
}
return s;
}
public static char[] convert2chararray(this int[] temp)
{
List<char> ls = new List<char>();
for (int i = 0; i < temp.Length; i++)
{
ls.Add((char)temp[i]);
}
return ls.ToArray();
}
public static int[] sort(this int[] temp)
{
List<int> ls;
ls = temp.ToList();
ls.Sort();
return ls.ToArray();
}
public static int[] convert2int(this string temp)
{
List<int> ls = new List<int>();
for (int i = 0; i < temp.Length; i++)
{
ls.Add((int)temp[i]);
}
return ls.ToArray();
}
public static byte ToTinyInt(this string temp)
{
return Convert.ToByte(temp);
}
public static void show(this byte temp)
{
Console.WriteLine(temp);
wline();
}
public static int[,] init(this int[,] temp)
{
Random rm = new Random();
int rank = temp.Rank;
int line = temp.GetLength(0);
int row = temp.Length / line;
for (int j = 0; j < line; j++)
{
for (int i = 0; i < row; i++)
{
temp[j, i] = rm.Next(9);
}
}
return temp;
}
public static string init(this string s,int lenght)
{
string temp = "";
Random rm = new Random();
for (int i = 0; i < lenght; i++)
{
temp += ((char)rm.Next(65, 90)).ToString();
}
return temp;
}
public static int[] init(this int[] temp)
{
Random rm = new Random();
for (int i = 0; i < temp.Length; i++)
{
temp[i] = rm.Next(10000);
}
return temp;
}
#region
public static void show(this string temp)
{
Console.WriteLine(temp);
wline();
}
public static void show(this int[,] temp)
{
int rank = temp.Rank;
int line = temp.GetLength(0);
int row = temp.Length / line;
for (int j = 0; j < line; j++)
{
for (int i = 0; i < row; i++)
{
Console.Write(temp[j, i] + " ");
}
Console.WriteLine();
}
wline();
}
public static void show(this int[] temp)
{
for (int i = 0; i < temp.Length; i++)
{
Console.Write(temp[i] + " ");
}
Console.WriteLine();
wline();
}
#endregion
public static void wline()
{
Console.WriteLine("-------------------------------------------------------------------");
}
}
}
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace baidu
{
class temp
{
public static void main()
{
string s = "25";
s.ToTinyInt().show();
}
}
public static class MyExtensions
{
public static string sort(this string temp)
{
return temp.convert2int().sort().convert2chararray().CharToString();
}
public static string CharToString(this char[] temp)
{
string s = "";
for (int i = 0; i < temp.Length; i++)
{
s += temp[i].ToString();
}
return s;
}
public static char[] convert2chararray(this int[] temp)
{
List<char> ls = new List<char>();
for (int i = 0; i < temp.Length; i++)
{
ls.Add((char)temp[i]);
}
return ls.ToArray();
}
public static int[] sort(this int[] temp)
{
List<int> ls;
ls = temp.ToList();
ls.Sort();
return ls.ToArray();
}
public static int[] convert2int(this string temp)
{
List<int> ls = new List<int>();
for (int i = 0; i < temp.Length; i++)
{
ls.Add((int)temp[i]);
}
return ls.ToArray();
}
public static byte ToTinyInt(this string temp)
{
return Convert.ToByte(temp);
}
public static void show(this byte temp)
{
Console.WriteLine(temp);
wline();
}
public static int[,] init(this int[,] temp)
{
Random rm = new Random();
int rank = temp.Rank;
int line = temp.GetLength(0);
int row = temp.Length / line;
for (int j = 0; j < line; j++)
{
for (int i = 0; i < row; i++)
{
temp[j, i] = rm.Next(9);
}
}
return temp;
}
public static string init(this string s,int lenght)
{
string temp = "";
Random rm = new Random();
for (int i = 0; i < lenght; i++)
{
temp += ((char)rm.Next(65, 90)).ToString();
}
return temp;
}
public static int[] init(this int[] temp)
{
Random rm = new Random();
for (int i = 0; i < temp.Length; i++)
{
temp[i] = rm.Next(10000);
}
return temp;
}
#region
public static void show(this string temp)
{
Console.WriteLine(temp);
wline();
}
public static void show(this int[,] temp)
{
int rank = temp.Rank;
int line = temp.GetLength(0);
int row = temp.Length / line;
for (int j = 0; j < line; j++)
{
for (int i = 0; i < row; i++)
{
Console.Write(temp[j, i] + " ");
}
Console.WriteLine();
}
wline();
}
public static void show(this int[] temp)
{
for (int i = 0; i < temp.Length; i++)
{
Console.Write(temp[i] + " ");
}
Console.WriteLine();
wline();
}
#endregion
public static void wline()
{
Console.WriteLine("-------------------------------------------------------------------");
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询