本文整理汇总了C#中System.Data.SqlTypes.SqlChars.SetLength方法的典型用法代码示例。如果您正苦于以下问题:C# SqlChars.SetLength方法的具体用法?C# SqlChars.SetLength怎么用?C# SqlChars.SetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlTypes.SqlChars
的用法示例。
在下文中一共展示了SqlChars.SetLength方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SqlCharsSetLength
public void SqlCharsSetLength ()
{
char [] b1 = new char [10];
SqlChars chars = new SqlChars ();
try {
chars.SetLength (20);
Assert.Fail ("Should throw SqlTypeException");
} catch (Exception ex) {
Assert.AreEqual (typeof (SqlTypeException), ex.GetType (), "Should throw SqlTypeException");
}
chars = new SqlChars (b1);
Assert.AreEqual (chars.Length, 10, "#1 Should be same");
try {
chars.SetLength (-1);
Assert.Fail ("Should throw ArgumentOutOfRangeException");
} catch (Exception ex) {
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "Should throw ArgumentOutOfRangeException");
}
try {
chars.SetLength (11);
Assert.Fail ("Should throw ArgumentOutOfRangeException");
} catch (Exception ex) {
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "Should throw ArgumentOutOfRangeException");
}
chars.SetLength (2);
Assert.AreEqual (chars.Length, 2, "#2 Should be same");
}
示例2: SqlCharsSetLength
public void SqlCharsSetLength()
{
char[] b1 = new char[10];
SqlChars chars = new SqlChars();
try
{
chars.SetLength(20);
Assert.False(true);
}
catch (Exception ex)
{
Assert.Equal(typeof(SqlTypeException), ex.GetType());
}
chars = new SqlChars(b1);
Assert.Equal(chars.Length, 10);
try
{
chars.SetLength(-1);
Assert.False(true);
}
catch (Exception ex)
{
Assert.Equal(typeof(ArgumentOutOfRangeException), ex.GetType());
}
try
{
chars.SetLength(11);
Assert.False(true);
}
catch (Exception ex)
{
Assert.Equal(typeof(ArgumentOutOfRangeException), ex.GetType());
}
chars.SetLength(2);
Assert.Equal(chars.Length, 2);
}