本文整理汇总了C#中String.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# String.GetLength方法的具体用法?C# String.GetLength怎么用?C# String.GetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String.GetLength方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(String[] args) {
int n = 100;
if (args.GetLength(0) >= 1) n = int.Parse(args[0]);
n = n / 2 * 2;
matmul_v1 m = new matmul_v1();
double[,] a, b, x;
a = m.matgen(n);
b = m.matgen(n);
x = m.matmul(a, b);
Console.WriteLine(x[n/2,n/2]);
}
示例2: getCustomerNamesAndIDs
/// <summary>
/// getCustomerNamesAndIDs()
/// returned array has as many elements in the first dimension
/// as there are records
/// It has two elements in the second dimension
/// </summary>
/// <returns>A 2 dimensional string array
/// </returns>
public String[,] getCustomerNamesAndIDs()
{
String[,] nameAndIDList = null;
// Allocate the 2 d array
nameAndIDList = new String[customers.GetLength(0), 2];
// load the array
for (int i = 0; i < nameAndIDList.GetLength(0); i++)
{
nameAndIDList[i, 0] = customers[i, 1];
nameAndIDList[i, 1] = customers[i, 0];
}
return nameAndIDList;
}
示例3: Mapstring
//Vorlesung bla bla bla
public void Mapstring(Bitmap mask)
{
StreamWriter text;
text = new StreamWriter("C:/Users/" + Environment.UserName + "/Desktop/IslandData.txt");
String[,] tiles = new String[mask.Width, mask.Height];
String[,] tilesgrav = new String[mask.Width, mask.Height];
for (int i = 0; i < tiles.GetLength(0); ++i)
{
for (int j = 0; j < tiles.GetLength(1); ++j)
{
if (mask.GetPixel(i, j).Name.Equals(black))
{
if ((i < 30 || i > mask.Width - 30 || j < 30 || j > mask.Height - 30))
{
tiles[i, j] = tilesgrav[i, j] = "false";
}
else
{
tiles[i, j] = "false";
tilesgrav[i, j] = "false";
}
}
else
{
tiles[i, j] = tilesgrav[i, j] = "true";
}
}
}
//System.IO.File.Create("Collision.txt");
//System.IO.File.Create("Collisiongrav.txt");
//System.IO.File.WriteAllText("Collision.txt", );
//System.IO.File.WriteAllText("Collisiongrav.txt", tilesgrav.ToString());
}
示例4: runTest
public Boolean runTest()
{
Console.Error.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
String strLoc = "Loc_000oo";
String strBaseLoc;
short[] in2Arr = new Int16[10];
int[] in4Arr = new Int32[5];
long[] in8Arr = new Int64[0];
String[] strArr = new String[6];
Boolean[] boArr = new Boolean[3];
Double[] dblArr = new Double[2];
Single[] snglArr = new Single[32000];
Char[] chArr = new Char[10000];
int rank;
try {
LABEL_860_GENERAL:
do
{
strLoc = "Loc_819yt";
rank = -1;
in2Arr = new Int16[5];
iCountTestcases++;
try {
in2Arr.GetLength(rank);
iCountErrors++;
Console.WriteLine( s_strTFAbbrev+ "Err_499ws! , GetLength=="+in2Arr.Length);
} catch (IndexOutOfRangeException ioorExc) {}
catch (Exception exc) {
iCountErrors++;
Console.WriteLine( s_strTFAbbrev+ "Err_758! exc=="+exc);
}
strLoc = "Loc_819ee";
rank = 1;
in2Arr = new Int16[5];
iCountTestcases++;
try {
in2Arr.GetLength(rank);
iCountErrors++;
Console.WriteLine( s_strTFAbbrev+ "Err_500ws! , GetLength=="+in2Arr.Length);
} catch (IndexOutOfRangeException ioorExc) {}
catch (Exception exc) {
iCountErrors++;
Console.WriteLine( s_strTFAbbrev+ "Err_750! exc=="+exc);
}
strLoc = "Loc_482wu";
rank = 0;
in2Arr = new Int16[10];
iCountTestcases++;
if(in2Arr.GetLength(rank) != 10)
{
iCountErrors++;
Console.WriteLine( s_strTFAbbrev+ "Err_481ua! , GetLength=="+in2Arr.Length);
}
strLoc = "Loc_471ay";
in4Arr = new Int32[5];
iCountTestcases++;
if(in4Arr.GetLength(rank) != 5)
{
iCountErrors++;
Console.WriteLine( s_strTFAbbrev+ "Err_29qaq! , GetLength=="+in4Arr.Length);
}
strLoc = "Loc_982uq";
in8Arr = new Int64[0];
iCountTestcases++;
if(in8Arr.GetLength(rank) != 0)
{
iCountErrors++;
Console.WriteLine( s_strTFAbbrev+ "Err_237sy! , GetLength=="+in8Arr.Length);
}
strLoc = "Loc_172ms";
boArr = new Boolean[3];
iCountTestcases++;
if(boArr.GetLength(rank) != 3)
{
iCountErrors++;
Console.WriteLine( s_strTFAbbrev+ "Err_382! , GetLength=="+boArr.Length);
}
strLoc = "Loc_49su";
dblArr = new Double[2];
iCountTestcases++;
if(dblArr.GetLength(rank) != 2)
{
iCountErrors++;
Console.WriteLine( s_strTFAbbrev+ "Err_200su! , GetLength=="+dblArr.Length);
}
strLoc = "Loc_371su";
snglArr = new Single[32000];
iCountTestcases++;
if(snglArr.GetLength(rank) != 32000)
{
iCountErrors++;
Console.WriteLine( s_strTFAbbrev+ "Err_319aw! , GetLength=="+snglArr.Length);
}
strLoc = "Loc_129wi";
strArr = new String[5];
strArr[2] = null;
iCountTestcases++;
if(strArr.GetLength(rank) != 5)
//.........这里部分代码省略.........
示例5: SampleRatesEqual
/// <summary>
/// Returns whether or not the sample rates in a set of WAV files are equal.
/// </summary>
/// <param name="pFileList">An array containing the names of the files to check</param>
/// <returns>Whether or not all WAV files have the same sample rate</returns>
private static bool SampleRatesEqual(String[] pFileList)
{
bool sampleRatesMatch = true;
if (pFileList != null)
{
int numFiles = pFileList.GetLength(0);
if (numFiles > 1)
{
int firstSampleRate = GetAudioFormat(pFileList[0]).SampleRateHz;
for (int i = 1; i < numFiles; ++i)
{
if (GetAudioFormat(pFileList[i]).SampleRateHz != firstSampleRate)
{
sampleRatesMatch = false;
break;
}
}
}
}
else
sampleRatesMatch = false;
return sampleRatesMatch;
}
示例6: MergeAudioFiles
/// <summary>
/// Merges a set of WAV file sinto a single WAV file in such a way that the audio will be overlayed.
/// This method will throw a WAVFileException upon error.
/// </summary>
/// <param name="pFileList">An array containing the audio filenames</param>
/// <param name="pOutputFilename">The name of the file to contain the resulting audio</param>
/// <param name="pTempDir">The full path to the temporary directory to use for the work. If this directory does not exist, it will be created and then deleted when this method no longer needs it.</param>
public static void MergeAudioFiles(String[] pFileList, String pOutputFilename, String pTempDir)
{
// If pFileList is null or empty, then just return.
if (pFileList == null)
return;
if (pFileList.GetLength(0) == 0)
return;
// Make sure all the audio files have the sample rate (we can merge 8-bit and 16-bit audio and
// convert mono to stereo). If the sample rates don't match, then throw an exception.
if (!SampleRatesEqual(pFileList))
throw new WAVFileAudioMergeException("The sample rates of the audio files differ.", "WAVFile.MergeAudioFiles()");
// Check the audio format. If the number of bits/sample or sample rate is not
// supported, then throw an exception.
WAVFormat firstFileAudioFormat = GetAudioFormat(pFileList[0]);
if (!SupportedBitsPerSample(firstFileAudioFormat.BitsPerSample))
throw new WAVFileBitsPerSampleException("Unsupported number of bits per sample: " + firstFileAudioFormat.BitsPerSample.ToString(), "WAVFile.MergeAudioFiles()", firstFileAudioFormat.BitsPerSample);
if (!SupportedSampleRate(firstFileAudioFormat.SampleRateHz))
throw new WAVFileSampleRateException("Unsupported sample rate: " + firstFileAudioFormat.SampleRateHz.ToString(), "WAVFile.MergeAudioFiles()", firstFileAudioFormat.SampleRateHz);
// 2. Create the temporary directory if it doesn't exist already. This checks for the
// existence of the temp directory and stores the result in tempDirExisted so that
// later, if the temp directory did not exist, we can delete it.
bool tempDirExisted = Directory.Exists(pTempDir);
if (!tempDirExisted)
{
try
{
Directory.CreateDirectory(pTempDir);
if (!Directory.Exists(pTempDir))
throw new WAVFileAudioMergeException("Unable to create temporary work directory (" + pTempDir + ")", "WAVFile.MergeAudioFiles()");
}
catch (Exception ex)
{
throw new WAVFileAudioMergeException("Unable to create temporary work directory (" + pTempDir + "): "
+ ex.Message, "WAVFile.MergeAudioFiles()");
}
}
// 4. Find the highest sample value of all files, and calculate the sound
// multiplier based on this (all files will be scaled down by this amount).
int numTracks = pFileList.GetLength(0);
double multiplier = 0.0; // The multiplier for scaling down the audio files
short highestSampleValue = 0; // Will store the highest sample value (8-bit will be cast to short)
// Determine the highest # of bits per sample in all the audio files.
short highestBitsPerSample = HighestBitsPerSample(pFileList);
bool outputStereo = (HighestNumChannels(pFileList) > 1);
if (highestBitsPerSample == 8)
{
// Get the highest sample value of all of the WAV files
byte highestSample = HighestSampleValue_8bit(pFileList);
highestSampleValue = (short)highestSample;
byte difference = (byte)(highestSample - (byte.MaxValue / (byte)numTracks));
multiplier = 1.0 - ((double)difference / (double)highestSample);
}
else if (highestBitsPerSample == 16)
{
// Get the highest sample value of all of the WAV files
highestSampleValue = HighestSampleValueAs16Bit(pFileList);
short difference = (short)(highestSampleValue - (short.MaxValue / (short)numTracks));
multiplier = 1.0 - ((double)difference / (double)highestSampleValue);
}
if (double.IsInfinity(multiplier) || (multiplier == 0.0))
{
// If the temp dir did not exist, then remove it.
if (!tempDirExisted)
DeleteDir(pTempDir);
// Throw the exception
throw new WAVFileAudioMergeException("Could not calculate first volume multiplier.", "WAVFile.MergeAudioFiles()");
}
if (multiplier < 0.0)
multiplier = -multiplier;
// 5. Scale down the audio levels of the source files, and save the output
// in the temp directory. Also change the path to the audio files in
// inputFilenames so that they point to the temp directory (we'll be
// combining the scaled audio files).
// This array (scaledAudioFiles) will contain WAVFile objects for the scaled audio files.
WAVFile[] scaledAudioFiles = new WAVFile[pFileList.GetLength(0)];
String filename = ""; // For the scaled-down WAV filename
WAVFile inputFile = new WAVFile();
WAVFile outputFile = new WAVFile();
for (int i = 0; i < pFileList.GetLength(0); ++i)
{
// pFileList[i] contains the fully-pathed filename. Using just the
// filename, construct the fully-pathed filename for the scaled-down
// version of the file in the temporary directory.
filename = pTempDir + "\\" + Path.GetFileName(pFileList[i]);
//.........这里部分代码省略.........
示例7: ConfigureSpeechRecognition
private bool ConfigureSpeechRecognition()
{
/* Create the AudioSource instance */
source = session.CreateAudioSource();
/* Set audio volume to 0.2 */
source.SetVolume(0.2f);
/* Set Audio Source */
source.SetDevice(sourceDeviceInfo[_activeSource]);
pxcmStatus sts = session.CreateImpl<PXCMSpeechRecognition>(out sr);
if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR)
{
/* Configure */
PXCMSpeechRecognition.ProfileInfo pinfo;
sr.QueryProfile(_activeLanguage, out pinfo);
sr.SetProfile(pinfo);
/* Set Command/Control or Dictation */
string[] cmds = new String[4] { "Create", "Save", "Load", "Run" };
if (cmds != null && cmds.GetLength(0) != 0)
{
// voice commands available, use them
sr.BuildGrammarFromStringList(1, cmds, null);
sr.SetGrammar(1);
}
}
else
{
Debug.Log("VoiceThreadError - InitFailed - CreateImpl!");
return false;
}
return true;
}