Your variable is used outside the do/while (in C# the curlies typically define the scope) and since it is declared inside the do-while, you cannot use it outside that scope.
You can fix this by simply declaring it outside the loop.
int composite = 0; // you are not required to set it to zero, as long
// as you do not use it before you initialize it
do
{
index += index;
composite = index + 1;
// more code here
} while (UnsetBitmask(bitmasks, composite));
Note (1), it is common practice to declare and set a variable in one go, but this is not a requirement, as long as you set it before you use it.
Note (2): in C#, curly braces {....}
define the scope of variables. You cannot use a variable outside its scope, it is not "visible" anymore, in fact, once it goes out of scope, it is ready to be garbage collected and its contents can be undefined.
i konw this,but why compiler cant do this
You asked this in the comments. The answer is less trivial than it may seem. It highly depends on the language definition. Some languages, like Perl, or older BASIC, allow variables to be declared at any level and in any scope. Other languages allow scoping of variables and require variables to be declared prior to their use (C#, Java, C++, Python). Usually, but not necessarily, this is common for statically typed languages, as the compiler needs to know beforehand what type of data you want to put in the variable, in order to do type checking.
If a compiler would force declaration, but not scope, it means that all variables would be global, which is hard in larger programs, as as a programmer, you will have to maintain where you used what variable names and maintain uniqueness. This is very tedious (think COBOL).
C# added the dynamic
keyword, which allows for variables that have dynamic type, but this still requires you to define the variable prior to its use.
A compiler can do this, but the designers of C# have decided that clear language is better, and in their opinion, declared variables are a good thing, because it prevents spurious errors and impossible-to-follow code:
// can you see the problem?
va1l = 1;
val1 = 2;
vall = va1l + vall;
Forcing you to declare variables and to have them scoped prevents this and related kinds of errors.