﻿<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title> Find maximum of all elements </Title>
            <Description> Expansion snippet to find maximum value of all elements in an array. </Description>
            <Author>Microsoft Corporation</Author>
            <SnippetTypes>          
                <SnippetType> Expansion </SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID> Array </ID>
                    <Default > nArray </Default>
                    <ToolTip> Array containing elements. </ToolTip>
                </Literal>
            </Declarations>
            <Code Language="vjsharp" Format="CData"><![CDATA[
int nMaxValue = 0;

//Check the array has any elements or not
if (null != $Array$ && $Array$.length > 0)
{
    //Set the value of first element of the array as maximum initially
    nMaxValue = $Array$[0];

    for (int i = 1; i < $Array$.length; i++)
    {
        //If the array has a value greater than the maximum value we have
        //set the value as the maximum value
        if (nMaxValue  < $Array$[i])
        {
            nMaxValue  = $Array$[i];
        }
    }
}
$selected$ $end$
]]>
</Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>
